With the following code
The array length is 7 the first time, but 6 the second time. This causes an out of range exception if I try to read TestArray(6). I Thought that using
would mean the array always had seven elements. Do I have to test the array length before reading or is there a way around this ?
If the string is "1,2,3,4,5,," then TestArray.Length is only 5.
I think that Regex.Split() should return a seven element array even if the string is ",,,,,," (Length is 1 for this) otherwise a lot of what if code will be required depending on the input data.
B4X:
Sub Activity_Create(FirstTime As Boolean)
Dim TestArray(7) As String
TestArray=Regex.Split(",","1,2,3,4,5,6,7")
Msgbox(TestArray.Length,"")
TestArray=Regex.Split(",","1,2,3,4,5,6,")
Msgbox(TestArray.Length,"")
End Sub
B4X:
Dim TestArray(7) As String
If the string is "1,2,3,4,5,," then TestArray.Length is only 5.
I think that Regex.Split() should return a seven element array even if the string is ",,,,,," (Length is 1 for this) otherwise a lot of what if code will be required depending on the input data.
Last edited: