Mashiane Expert Licensed User Longtime User Nov 2, 2016 #1 Hi I have a string variable.. "LongDate;;", if I pass it to StrParse, which is just a RegEx.Split function, it returns a string array with a length of 1, however "LongDate; ; ", returns a string array with length 3. e.g. Dim spFormats() As String = StrParse(";", "LongDate;;") Code: Copy Sub FixDelimiter(sValue As String) As String If sValue = "|" Then sValue = "\|" If sValue = "." Then sValue = "\." If sValue = "\" Then sValue = "\\" If sValue = "^" Then sValue = "\^" If sValue = "$" Then sValue = "\$" If sValue = "?" Then sValue = "\?" If sValue = "*" Then sValue = "\*" If sValue = "+" Then sValue = "\+" If sValue = "(" Then sValue = "\(" If sValue = ")" Then sValue = "\)" If sValue = "[" Then sValue = "\[" If sValue = "{" Then sValue = "\{" If sValue = ";" Then sValue = "\;" Return sValue End Sub Code: Copy Sub StrParse(Delimiter As String, MV As String) As String() Delimiter = FixDelimiter(Delimiter) Return Regex.Split(Delimiter, MV) End Sub
Hi I have a string variable.. "LongDate;;", if I pass it to StrParse, which is just a RegEx.Split function, it returns a string array with a length of 1, however "LongDate; ; ", returns a string array with length 3. e.g. Dim spFormats() As String = StrParse(";", "LongDate;;") Code: Copy Sub FixDelimiter(sValue As String) As String If sValue = "|" Then sValue = "\|" If sValue = "." Then sValue = "\." If sValue = "\" Then sValue = "\\" If sValue = "^" Then sValue = "\^" If sValue = "$" Then sValue = "\$" If sValue = "?" Then sValue = "\?" If sValue = "*" Then sValue = "\*" If sValue = "+" Then sValue = "\+" If sValue = "(" Then sValue = "\(" If sValue = ")" Then sValue = "\)" If sValue = "[" Then sValue = "\[" If sValue = "{" Then sValue = "\{" If sValue = ";" Then sValue = "\;" Return sValue End Sub Code: Copy Sub StrParse(Delimiter As String, MV As String) As String() Delimiter = FixDelimiter(Delimiter) Return Regex.Split(Delimiter, MV) End Sub
Erel B4X founder Staff member Licensed User Longtime User Nov 3, 2016 #2 I'm pretty sure that there is no bug here. Can you post the code that reproduces it?
Mashiane Expert Licensed User Longtime User Nov 3, 2016 #3 Erel said: I'm pretty sure that there is no bug here. Can you post the code that reproduces it? Click to expand... Found a solution, sorry apparently its not a bug. I just read that Regex removes the trailing items when for example you try and split "variable,,," so i added a space after my variable making it "variable,,, " and thus it works properly now. Other people here it seems had the same problem, i should have searched some more. false alarm. https://www.b4x.com/android/forum/threads/closed-regex-split.61728/#post-389546 Last edited: Nov 3, 2016
Erel said: I'm pretty sure that there is no bug here. Can you post the code that reproduces it? Click to expand... Found a solution, sorry apparently its not a bug. I just read that Regex removes the trailing items when for example you try and split "variable,,," so i added a space after my variable making it "variable,,, " and thus it works properly now. Other people here it seems had the same problem, i should have searched some more. false alarm. https://www.b4x.com/android/forum/threads/closed-regex-split.61728/#post-389546
S sorex Expert Licensed User Longtime User Nov 3, 2016 #4 normal behaviour as regex.split tends to drop empty ending elements.