Convert a string to a number

Hi Guys,

I’m a new user on Uipath,and I’m facing my first problem trying to conver a string to a number.

I’m getting values from a DataTable into a variable (Heure_Minute_Actuelle_Row) :
row(2).ToString.Substring(9,2)+row(2).ToString.Substring(12,2) --> Result is 1032 (as a string)

Then :
I try to convert as number what I get into Heure_Minute_Actuelle_Row (so 1032) by assigning in a new variable (Heure_Minute_Actuelle_Row_Number) --> cint(Heure_Minuite_Row) and I get 0 as number

Could someone help on this topic how to convert this string into a number ?

Thanks a lot.

Hi @Sandro,

For converting a string to number, use the following code

integer.Parse("1032") returns 1032 as integer.

Hope it helps!
Thanks,
Saranya K R

2 Likes

you can try this.

convert.ToInt32(k)

1 Like

Hello Saranya,

Tkanks for you answer. I always get 0 into my variable using Interger.Parse code. I’ve also tried to use "Convert.ToInt32, but always the same…

Is it possible to send the workflow?

Actually you should send the xaml, not a screenshot.

As @c.ciprian mentioned, please do send the xaml with dummy data.

Ok sorry

I get an error message (Sorry new users cannot upload attachements)

send me the query what u wrote? @Sandro

@arivu96 Are u talking about this query ?

row(2).ToString.Substring(9,2)+row(2).ToString.Substring(12,2) --> Result is 1032 (as a string)

Then :
I try to convert as number what I get into Heure_Minute_Actuelle_Row (so 1032) by assigning in a new variable (Heure_Minute_Actuelle_Row_Number) --> cint(Heure_Minuite_Row) and I get 0 as number

I found the solution --> Convert.ToInt16…

I don’t get where the issue is.


image
CInt(variable1+variable2)*10

Multiplied by 10 to check that it really is a number

This should be:
CInt(variable1)+CInt(variable2)
You need to convert each variable individually if they are strings, or it will use string concatenation.

You could also check if it’s a number before the conversion too like this:
If(IsNumeric(variable1), CInt(variable1), 0) + If(IsNumeric(variable2), CInt(variable2), 0)

1 Like

He wants to concatenate the strings, then convert to number. The additional check that it is a number is good practice indeed.

:+1: gotcha

Thanks to all of you for your help ! My issue is resolved. Have a nice day