Bug? Regex.split Difference between B4A and B4J?

jmon

Well-Known Member
Licensed User
Longtime User
Hello,

I bumped into something weird. The Regex.split apparently behaves differently between B4J and B4A.

Please try this in B4A and B4J:
B4X:
Dim Name As String = "Robert"
Dim Letters() As String = Regex.Split("", Name)   
   
For i = 0 To letters.Length -1
    Log("Letter " & i & " = " & Letters(i))
Next

In B4J, I get this in the log (which I consider correct):
Letter 0 = R
Letter 1 = o
Letter 2 = b
Letter 3 = e
Letter 4 = r
Letter 5 = t
Note that letter 0 is 'R'

but in B4A I get that:
Letter 0 =
Letter 1 = R
Letter 2 = o
Letter 3 = b
Letter 4 = e
Letter 5 = r
Letter 6 = t
Note that letter 0 is ''

I found that because I usually test my code on B4J. i'm using B4A 3.82 and B4J 2.20. It is a bug?

Thank you,
jmon
 

jmon

Well-Known Member
Licensed User
Longtime User
It is wrong to split on an empty string. You should instead use Name.CharAt.
Thanks,
I'll try that. I am trying to have all the letters in an array, so your method will work.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…