天天看點

Why can be so about Regex.IsMatch with double backslash?

In C #, / is the escape character, character escape sequences as follows

/' Single quote

/" Double quote

// Backslash

/0 null

/a warning

/b backspace

/f new page

/n new line

/r enter

/t horizontal tab

/v vertical tab

string str= "The destination 'c://test.txt' already exists.";

string strP = "The destination 'c://test.txt' already exists.";

Console.WriteLine(str);

Console.WriteLine(strP);

Console.WriteLine("Done");

bool a = Regex.IsMatch(

str,

strP,

RegexOptions.IgnoreCase);

Console.WriteLine(a);

Console.Read();

//value of a is False, so the double backslash will affect the result

strP.Replace(@"/", @"//"),

//value of a is True,but i don't know why