Convert string to int

After I have used ‘get text’ function to retrieve a number from a website, I would like to convert the number from string to int. The number is now in the format 1.495,20.

I have tried using .Replace to remove “.” and “,”.

When I replace “.” with “” I get 1495,20. But then, when I try replacing “,” with “” I get an error saying that Open Strict On does not allow implicit conversions from string to int.

How do I then get a variable with the number 149520?

2 Likes

Hi there. You might need to do a convert also to resolve the error.
For example,
CInt(“1.495,20”.Replace(“.”,“”).Replace(“,”,“”).Trim)
or
Convert.ToInt32(“1.495,20”.Replace(“.”,“”).Replace(“,”,“”).Trim)

I put in .Trim incase you have any spaces.

Another method is to extract only the digits out.
CInt(String.Concat(“1.495,20”.Where(AddressOf Char.IsDigit)))
or
CInt(System.Text.RegularExpressions.Regex.Replace(“1.495,20”, “[^0-9]”, “”))

Regards!

11 Likes

You can also try something like

Int32.parse(“1.495,20”.Replace(“.”,“”).Replace(“,”,“”))

2 Likes

Hi,

You can try Regex.Replace and Convert.ToInt
For Example…
Convert.ToInt32(Regex.Replace(“1,245.00”,“[,|.]”,“”).ToString)

Regards,

1 Like

This worked like a charm! And thank you for the additional input, it will be handy later on :slight_smile:


try this one…

6 Likes

@VISHNU07 Thank you for this…

Thx a lot that was very helpful!

this is not working for me… could you please help me…

Hi @Sasidhar143

Can you print the value in the variable Get_initial_price and see whether there are any spaces or any special characters in the string?

Also, what error are you getting when trying to convert it?

1 Like

Thanks Lot…this is working…actually it contains coma so it was throwing error.

image

1 Like

It’s really to help me. Thanks!
From my example:

strVar = CurrentRow.Item("strPrice").ToString
CurrentRow.Item("Price") = strVar.Replace("₴","").Replace(" ","").Trim

Yes, it’s work…