B4J Question number within a string

luke2012

Well-Known Member
Licensed User
Longtime User
Hi to all,
how to extract a number within a string in B4J ?

I have a html input field formatted for the price input.
I read the value (.GetVal) in B4J and I got a string like this : "€ ___.___._22,10".

I need to extract the numeric part of the string. How to do this job in B4J ?
 

LucaMs

Expert
Licensed User
Longtime User
There is probably a better method.

You could use string functions.

B4X:
Private strPrice As String = "€ ___.___._22,10"
strPrice = strPrice.Replace(",", ".") ' <---- attention: it applies only to this example and for the Italian version
Private Price As Float
Price = strPrice.SubString(strPrice.LastIndexOf("_") + 1)
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

here is another solution:

B4X:
Dim s As String = "€ ___.___._22,10"
Dim sp() As String = Regex.Split("_", s)
Log("Price:" & sp(sp.Length - 1))
 
Upvote 0
Top