jmon Well-Known Member Licensed User Longtime User Oct 17, 2014 #1 Hello, I bumped into something weird. The Regex.split apparently behaves differently between B4J and B4A. Please try this in B4A and B4J: Code: Copy 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 Click to expand... 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 Click to expand... 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
Hello, I bumped into something weird. The Regex.split apparently behaves differently between B4J and B4A. Please try this in B4A and B4J: Code: Copy 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 Click to expand... 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 Click to expand... 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
Erel B4X founder Staff member Licensed User Longtime User Oct 19, 2014 #2 It is wrong to split on an empty string. You should instead use Name.CharAt.
jmon Well-Known Member Licensed User Longtime User Oct 19, 2014 #3 Erel said: It is wrong to split on an empty string. You should instead use Name.CharAt. Click to expand... Thanks, I'll try that. I am trying to have all the letters in an array, so your method will work.
Erel said: It is wrong to split on an empty string. You should instead use Name.CharAt. Click to expand... Thanks, I'll try that. I am trying to have all the letters in an array, so your method will work.