Android Question Regex split

Addo

Well-Known Member
Licensed User
Longtime User
i have this following text

B4X:
dim data as string = "Marten~Samuel~~~Martha~"
dim parser() As String

parser = Regex.Split("\~", data)


i expect to get Length of 5 , but i got Length of 3

why the empty ~ doesn't count in the parser ?
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
    Dim data As String = "Marten~Samuel~~~Martha~"
    Dim parser() As String

    parser = Regex.Split("~", data)
    Log($"Splitted Size: ${parser.Length} "$)
    For i= 0 To parser.Length-1
       Log($"Val #${i}=${parser(i)}"$)
   Next
Logs a size of 5 like i was expecting where #2 and #3 are empty.

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Splitted Size: 5
Val #0=Marten
Val #1=Samuel
Val #2=
Val #3=
Val #4=Martha
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
 
Upvote 0
Top