Covert String to Integer issue

I have string value input=“027” and need to subtract 1 from this input string. So output should come as 026.

I tried assign activity like below but output will come as 26 not like as we expected.
output=(interger.parse(input)-1).tostring

Thanks in advance…

@Mahesh_Bandi1

input = “027”
(Int32.Parse(input) - 1).ToString(“D3”)

Hi @Mahesh_Bandi1

use the below syntax
(Cint(Input)-1).ToString("D3")

Regards

Hi @Mahesh_Bandi1

You can convert the string datatype to integer by using CInt Function.

- Assign -> Input = "027"
- Assign -> Output = CInt(Input)-1

Hope it helps!!

Hi @Mahesh_Bandi1

input = "027"
output = (Integer.Parse(input) - 1).ToString("D3")

.ToString("D3") -->Converts the result back to a string and ensures it has three digits, adding leading zeros if necessary.

For more conversions, check this:

Hi @Mahesh_Bandi1

(Integer.Parse(Input) - 1).ToString("000")

Hi,

You subtract 1 from a string like “027” using the method you’ve described, it first converts the string to an integer, subtracts 1, and then converts it back to a string. The conversion to an integer removes the leading zero, resulting in “26” instead of “026.”

you can use below expression:

(Int32.Parse(“027”) - 1).ToString(“D3”)

@Mahesh_Bandi1

try this

output = If((Cint(input)-1).ToString.Count=2,"0","") + (Cint(input)-1).ToString

or use

Output = (Cint(input)-1).ToString.PadLeft(3, "0"c)

image

cheers

cheers

string input = "027";
int intValue = cint(input);

Thanks for your quick response but If I tired this way it is giving below error

@Mahesh_Bandi1

Can you try this

(Int32.Parse(input) - 1).ToString(“D3”)

Thanks @mkankatala
I tired this way already but it will give only 26 not as we expected.

Hi @Mahesh_Bandi1

Try this I have posted above

Regards

Okay @Mahesh_Bandi1

For that use can try in this way

- Assign -> Input = "027"
- Assign -> output = (CInt(Input)-1).toString("D3")

In this we mentioned the number of items we have. It will give the result as 026

Hope you understand!!

Thanks @irtetala
I tried this way but it is giving completion error. PFA

@Mahesh_Bandi1

Please retype double quotes

1 Like

@Mahesh_Bandi1

assign
strr=“027”

Assign

strr1=(CInt(strr)-1).ToString(“D3”)

(CInt(strr)-1).ToString("D3")


cheer…!

WORKS FINALLY… Double quotes I retyped then it works … :ok_hand:

I am very happy for all associate answers…Thanks a lot guys

1 Like

Please close this topic by marking the appropriate post as solution @Mahesh_Bandi1

Cheers!!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.