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?
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]”, “”))