Groups | Blog | Home
all groups > c# > april 2005 >

c# : What's wrong with this Regex.Split


Adam Clauss
4/12/2005 8:16:30 PM
Why not just:
string[] asTest =sTest.Split("||".ToCharArray());

--
Adam Clauss
cabadam@tamu.edu

[quoted text, click to view]

Jianwei Sun
4/12/2005 9:11:19 PM
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 Sun
4/12/2005 9:24:44 PM
This will return an array with three elements with one empty string
inside, instead of two. Still, appreciate your reply.
[quoted text, click to view]
Tim Wilson
4/12/2005 9:42:15 PM
Try escaping the pipes.

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

--
Tim Wilson
..Net Compact Framework MVP

[quoted text, click to view]

Adam Clauss
4/13/2005 7:36:18 AM
Ahhh.... you're absolutely right - sorry!

--
Adam Clauss
cabadam@tamu.edu

[quoted text, click to view]

Jianwei Sun
4/13/2005 8:02:31 AM
Work beautifully, thanks.

John
[quoted text, click to view]
AddThis Social Bookmark Button