slugger Member Licensed User Longtime User Nov 21, 2013 #1 Hello, consider the following code: Code: Copy 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: Code: Copy 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?
Hello, consider the following code: Code: Copy 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: Code: Copy 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?
Erel B4X founder Staff member Licensed User Longtime User Nov 21, 2013 #2 Regex.Split discards trailing empty strings. This is how the native API works. You can check whether the last character is ',' and append another one. Upvote 0
Regex.Split discards trailing empty strings. This is how the native API works. You can check whether the last character is ',' and append another one.