Android Question Regex odd results

slugger

Member
Licensed User
Longtime User
Hello,

consider the following code:

B4X:
Dim s1(),s2 As String
s2="1,,3"
s1=Regex.Split(",",s2)

the s1 array has 3 strings, respectively "1","" and "3", that's ok.

Now consider the following example:

B4X:
Dim s1(),s2 As String
s2="1,2,"
s1=Regex.Split(",",s2)

This time the s1 array has only 2 elements, respectively "1" and "2", I would have expected a third empty element "" but that does not happen.

Why is regex working like this?

How can I get the s1 array with all the elements even if the last ones are empty strings?
 
Top