Wasted some time to debug an algorithm as I wasn't aware that the pipe character (|) in Regex is a special character and needs to be escaped. Took some time to pinpoint the problem and made the mistake to not search the forum and coded a split function:
This works all fine, but then did a forum search for Regex, pipe and found the simple solution.
I did look at the RegEx.Split help popup, but no mention of this. I think the pipe character is a
common character used as a separator, so I have a feeling I am not the first one to have made
this mistake (as indeed the forum search showed) and maybe this could be added to the popup
help.
RBS
B4X:
Sub Split(strSplitter As String, strToSplit As String) As String()
Dim i As Int
Dim n As Int
Dim iPos As Int
Dim iPosOld As Int
iPos = strToSplit.IndexOf(strSplitter)
If iPos = -1 Then
Dim arrSplit(1) As String
arrSplit(0) = strToSplit
Return arrSplit
End If
Dim arrSplit(strToSplit.Length / 2 + 1) As String
arrSplit(n) = strToSplit.SubString2(0, iPos)
n = 1
Do While True
iPosOld = iPos
iPos = strToSplit.IndexOf2(strSplitter, iPosOld + 1)
If iPos = -1 Then Exit
arrSplit(n) = strToSplit.SubString2(iPosOld + 1, iPos)
n = n + 1
Loop
'add any trailing item
If iPosOld < strToSplit.Length - 1 Then
arrSplit(n) = strToSplit.SubString(iPosOld + 1)
n = n + 1
End If
Dim arrSplit2(n) As String
For i = 0 To n - 1
arrSplit2(i) = arrSplit(i)
Next
Return arrSplit2
End Sub
This works all fine, but then did a forum search for Regex, pipe and found the simple solution.
I did look at the RegEx.Split help popup, but no mention of this. I think the pipe character is a
common character used as a separator, so I have a feeling I am not the first one to have made
this mistake (as indeed the forum search showed) and maybe this could be added to the popup
help.
RBS