开发者

| as pattern when using split

string input = @"12.2.2010|7";   
string pattern = @"|";

foreach (string result in Regex.Split(input, pattern)) 
{
   Console.WriteLine("'{0}'", result);
}

i want to use | as patter but开发者_Go百科 becouse | means or i can't get 12.2.2010. How can i use | like pattern? I try to use ~ but is the same.


Try to escape the | like this

string pattern = @"\|";


In a regular expression, if you want to match a literal |, you need to escape it with a backslash, like so:

string pattern = @"\|";


The character | has a special meaning in a regular expression, which means you have to escape it with a \ like so:

string pattern = @"\|";

Check out the following website for some more information: http://www.regular-expressions.info/reference.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜