B4J Question Parsing ASCII Text With Regex.Split()

RichardN

Well-Known Member
Licensed User
Longtime User
I just ran into a rather annoying problem whilst trying to parse some text data files. Each record has ASCII text fields delimited on each line by the ASCII pipe symbol '|'.

B4X:
Dim Crowd As String = "Joe Bloggs|Alan Smith|George Brown"
   
    Dim People() As String = Regex.Split(".", Crowd)
       
    Dim Person As List
    Person.Initialize2(People)
   
    Dim count As Int
   
    For count = 0 To Person.Size -1
        Log(Person.Get(count))                  'unexpected results!
    Next


Each record has ASCII text delimited by the pipe symbol '|'. Unfortunately trying to parse this symbol using Regex.Split("|", Text) produces unexpected results. This is very unfortunate as this delimited format was once widely used.

It appears that commas work fine but attempting to use other ASCII meta-characters produces unexpected results or errors.

Which ASCII characters work as delimiters and which do not?
 

lemonisdead

Well-Known Member
Licensed User
Longtime User
Shouldn't the pipe being escaped ? Because pipe has a special meaning

\|
 
Upvote 0
Top