K Kiran Raotole Active Member Licensed User Jun 5, 2019 #1 My string = "AND051" How extract number from this string? like new variable = 051 / 51
Erel B4X founder Staff member Licensed User Longtime User Jun 5, 2019 #2 B4X: Dim s As String = "AND051" Dim m As Matcher = Regex.Matcher("\d+", s) If m.Find Then Dim number As Int = m.Match Log(number) End If Upvote 0
B4X: Dim s As String = "AND051" Dim m As Matcher = Regex.Matcher("\d+", s) If m.Find Then Dim number As Int = m.Match Log(number) End If
E emexes Expert Licensed User Jun 5, 2019 #3 https://regex101.com/ is good for exploring regular expressions (and for building them, too ;-) eg: Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jun 6, 2019 #4 Less polished but also useful: https://b4x.com:51041/regex_ws/index.html Upvote 0
E emexes Expert Licensed User Jun 6, 2019 #5 Erel said: Less polished but also useful Click to expand... I like that it provides the code. Upvote 0
trepdas Active Member Licensed User Feb 4, 2021 #6 Erel said: B4X: Dim s As String = "AND051" Dim m As Matcher = Regex.Matcher("\d+", s) If m.Find Then Dim number As Int = m.Match Log(number) End If Click to expand... How would I delete the numbers from the strings and keep only the "AND" ? B4X: oldstring = "AND051" newstring = "AND" Upvote 0
Erel said: B4X: Dim s As String = "AND051" Dim m As Matcher = Regex.Matcher("\d+", s) If m.Find Then Dim number As Int = m.Match Log(number) End If Click to expand... How would I delete the numbers from the strings and keep only the "AND" ? B4X: oldstring = "AND051" newstring = "AND"
Erel B4X founder Staff member Licensed User Longtime User Feb 4, 2021 #7 You should never post questions in old threads. Upvote 0
Q Quandalle Member Licensed User Feb 4, 2021 #8 In your case, you can also use the replace function B4X: Dim s As String = "AND051" Log(Regex.Replace("\D",s,"")) ' replace all non digit char by nothing -> "051" Log(Regex.Replace("\d",s,"")) ' replace all digit char by nothing -> "AND" n Upvote 0
In your case, you can also use the replace function B4X: Dim s As String = "AND051" Log(Regex.Replace("\D",s,"")) ' replace all non digit char by nothing -> "051" Log(Regex.Replace("\d",s,"")) ' replace all digit char by nothing -> "AND" n