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

4 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:

@vsivaraman81, Can you elaborate more on your issue? With screenshot or with the .xaml?

Hi Tharusha

I have a doubt regarding the same
Sum=(CInt(FirstNum)+CInt(SecNum)).ToString

i could see the message box value as false instead of 30 for below workflow
Please refer the snippet to help me on the same

@Singa_Amulya

Welcome to the community If you want you can also create a new topic!

Sum=(CInt(FirstNum)+CInt(SecNum)).ToString

In this remove: Sum=

You will get the expected output!

Regards,
Ajay Mishra

1 Like

This is an expression because you do not have Sum= inside double quotes. So what’s happening is it’s checking whether the value in the variable Sum = “30” and since it does not you get false.

If you want the message box to show Sum=30 then you have to do “Sum=” + (CInt(FirstNum)+CInt(SecNum)).ToString

we recommend to avoid log messages / write line / message boxes when the part implementation is to check. Instead we can work with debugging panels

when such a statement is needed (also could be shortened to the sum) we can do
grafik

for any further assistance just open a new topic and get individual help

You need to use the integer.tryParse, and perform some validation like if tryParse return 0 or null then this should go to exception, its give you this result only when sharing contain some string value

string num1 = “23”