0

I have a problem parsing a line with regex

This is the line it will parse (called string Line)

4\:0=10.000000\:20,0.000000\:1,0\:0

this is the code to seperate it in pieces:

string[] parts = Regex.Split(Line, "\\");

but it says:

"\" invalid \ at the end of the pattern

dunno what is means...

1
  • 1
    Why are you even using Regex.Split for this? Wouldn't a simple var parts = Line.Split('\\') do? Commented May 13, 2011 at 18:46

5 Answers 5

3

Why use a regex when string.Split will do?

string[] parts = Line.Split('\\');
Sign up to request clarification or add additional context in comments.

2 Comments

it cant, it must be a character then
@killie01 - No, it doesn't have to be. And `` is a character. Not sure what the problem is.
1

You either need to escape the slash "\\" or make it a literal string @"\".

Comments

0

You don't seem to have escaped the \.

try \\

Comments

0

Why not use String.Split() ?

And your trailing \ needs to be escaped thusly: \

Comments

0

If all you want to do is split a string into an array on a single character (backslash), try

string s = @"my\dog\has\fleas" ;
string[] words = s.split('\\') ;

Don't use a chainsaw if all you need is a paring knife.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.