What's wrong with this Regex.Split

  • Thread starter Thread starter Jianwei Sun
  • Start date Start date
J

Jianwei Sun

string sTest="TEST1||TEST2";
string[] asTest =Regex.Split(sTest, "||" );

I want to get an array with two elements TEST1 and TEST2, but it returs
every char inside the sTest as a seperate array element.

Thanks,
Jianwei
 
This will return an array with three elements with one empty string
inside, instead of two. Still, appreciate your reply.
 
Try escaping the pipes.

string sTest = "TEST1||TEST2";
string[] asTest = Regex.Split(sTest, @"\|\|");
 
Ahhh.... you're absolutely right - sorry!

--
Adam Clauss
(e-mail address removed)

Jianwei Sun said:
This will return an array with three elements with one empty string
inside, instead of two. Still, appreciate your reply.
Adam said:
Why not just:
string[] asTest =sTest.Split("||".ToCharArray());
 
Back
Top