B4J Question Replace Text in a string

Pelky

Active Member
Licensed User
Longtime User
I am trying to replace 5x spaces in a string with a comma "," - I have tried regex and ConvertString.Replace (" ", ",")
which I thought would be the easiest way but I am failing.
I have a string = "Booth 3 10:00 more guys a948484 23.01.2022"
and would like to create an array

if anyone can help it would be appreciated...
 

TILogistic

Expert
Licensed User
Longtime User
Replace multiple spaces in a string
B4X:
Regex.Replace("\s+",s," ")
demo:
B4X:
    Dim s As String = "Booth    3    10:00    more  guys  a948484    23.01.2022"
    Log(s)
   
    Dim ar() As String = Regex.Split(" ",Regex.Replace("\s+",s," "))
    Dim sb As StringBuilder
    sb.Initialize
    For Each m As String In ar
        Log(m)
        sb.Append(m).Append(" ")
    Next
    Log(sb.ToString)

1643302043993.png
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
other:
B4X:
    Dim s As String = "Booth    3    10:00    more  guys  a948484    23.01.2022"
    Log(Regex.Replace("\s+",s,","))
    
    For Each m As String In Regex.Split(",",Regex.Replace("\s+",s,","))
        Log(m)
    Next

1643302739580.png
 
Upvote 0
Top