luke2012 Well-Known Member Licensed User Longtime User Jul 23, 2014 #1 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 ?
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 Jul 23, 2014 #2 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
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)
rwblinn Well-Known Member Licensed User Longtime User Jul 23, 2014 #3 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
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))