Android Question Extract Number from alphanumeric string

trepdas

Active Member
Licensed User
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

How would I delete the numbers from the strings and keep only the "AND" ?
B4X:
oldstring = "AND051"
newstring = "AND"
 

Quandalle

Member
Licensed User
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
 
Top