开发者

Problem with regex parsing

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.00000开发者_开发百科0\: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...


Why use a regex when string.Split will do?

string[] parts = Line.Split('\\');


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


You don't seem to have escaped the \.

try \\


Why not use String.Split() ?

And your trailing \ needs to be escaped thusly: \


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜