Bug? Regex.Split error?

nibbo

Active Member
Licensed User
Longtime User
Hi

When using Regex.Split I get some funny results depending on the delimiter.
A couple of examples are:

Using a '$' dollar sign AA$BBB, the string is not split at all.
Using a '|' pipe AA|BBB results in 1 empty string and all other characters being separated out including the delimiter.
Examples below:
Code:
Dim string1 As String = "AA$BBB"
Log(string1)
Dim string2() As String = Regex.Split("$",string1)
For i = 0 To string2.Length - 1
Log("string2(" & i & ") = " & string2(i))
Next
Dim string3 As String = "AA|BBB"
Log(string3)
Dim string4() As String = Regex.Split("|",string3)
For i = 0 To string4.Length - 1
Log("string4(" & i & ") = " & string4(i))
Next

Results:
AA$BBB
string2(0) = AA$BBB
AA|BBB
string4(0) =
string4(1) = A
string4(2) = A
string4(3) = |
string4(4) = B
string4(5) = B
string4(6) = B

Is this by design?
Are there any other characters we should be avoiding?

Regards
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

Is this by design?
Yes. This is how regular expressions work. These are special characters. You need to escape them.
For further information please start a new thread in the questions forum.
 
Last edited:

Similar Threads

Top