Android Question how can i remove invalid characters from a string text and convert string number to double ?

Waldemar Lima

Active Member
Licensed User
hi everyone !

i am trying convert this string to Double : "-50.601713��MyDoubleVal"

i am using this code to do it :

B4X:
Dim TempVal As Double = StringInformation(2) ' here have double with string value
Log("My Double value is = "&TempVal)

but when i run this code i get this error : java.lang.NumberFormatException: Invalid double: "-50.601713��MyDoubleVal"
have a way to remove all string "��MyDoubleVal" from double ?
someone can help me ?
 

somed3v3loper

Well-Known Member
Licensed User
You can use Regex
B4X:
    Dim d As String ="-50.601713��MyDoubleVal"
    Dim ma As Matcher
    ma = Regex.Matcher("(-?[0-9]+(?:[,.][0-9]+)?)",d)
    If ma.Find Then
        Log(ma.Match)
    End If
 
Upvote 0
Top