Bug? RegEx Split Error

Mashiane

Expert
Licensed User
Longtime User
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;;")


B4X:
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

B4X:
Sub StrParse(Delimiter As String, MV As String) As String()
    Delimiter = FixDelimiter(Delimiter)
    Return Regex.Split(Delimiter, MV)
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
I'm pretty sure that there is no bug here. Can you post the code that reproduces it?
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:

sorex

Expert
Licensed User
Longtime User
normal behaviour as regex.split tends to drop empty ending elements.
 
Top