Adding string values

How to add two string values.
Ex: Num1=“23”
Num2=“34”

Sum=57

1 Like

hi @Girish26,

Welcome to the community. :slightly_smiling_face:
You can not perform arithmetic operations with string values directly. So if you want to add those two values, first you need to convert them into integers as below and add them.

string num1 = “23”
string num2 = “34”

string Sum = ( integer.Parse(num1) + integer.Parse(num2) ).ToString

Regards,
Tharusha

3 Likes

Hi,

Sum = (cint(Num1)+cint(Num2)).ToString

here the Sum is String Variable.

Hope this would be of help.

Regards,
Ashley Nihal Dcunha

3 Likes

@Tharusha_Jayadeera Thanks for your help.

1 Like

Hi
It will be helpfull if you provide me a solution for this.
I have two string variable which contains time format
variable 1 =“11:00”
variable 2 = “4:00”
i need add this two variable so that my output time will be “15:00”

@niranjanaa_sha

Try this:

String addTime = (timespan.parse(“11:00:00”)+timespan.parse(“4:00:00”)).Tostring

1 Like

Thanks Tharusha!! I tried addition of Two String variables using UiPath. It worked properly. Thanks for Best Solution provided by you.

Regards
Rohit Lanjewar

2 Likes

Hi @RohitSuperCool009 and @Girish26,

It’s my pleasure to help you. Cheers…:slightly_smiling_face:

Regards,
Tharusha

@niranjanaa_sha

Here, Start_Time and End_Time_Window variables should be string type. Have you declared it as string type or not ?

Show me what input you passed to those variables ?

@niranjanaa_sha

Try to print the value of Start_Time and End_Time and see once.

If possible share your workflow. Will check and update you.

And also here You declared Variable name as “End_Time” but in the previous post you are using as “End_Time_Window”. Check it that also.

Hy I did little bit changes in my code and its working fine now…

Thank You :slight_smile:

2 Likes

Hi,
i need to add “AA100275” +1.
does anyone have any suggestions?

thanks

add in what sense ? u want it as AA100276 or AA1002751?
if needed like AA1002751 then its straight forward “AA100275”+“1”
if needed like AA100276 then you have to split the string and then add 1 to the number part of it.

its done like this (insert this into the Message box activity)
System.Text.RegularExpressions.Regex.Matches(“AA100275”, “[A-z]+”)(0).ToString + (CInt(System.Text.RegularExpressions.Regex.Matches(“AA100275”, “\d+”)(0).ToString)+1).ToString

image

1 Like

Thank you…it’s fine :slight_smile: