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 w...

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 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.Replace(@"/", @"//"), RegexOptions.IgnoreCase); Console.WriteLine(a); Console.Read(); //value of a is True,but i don't know why

目录
打赏
0
0
0
0
20
分享
相关文章
数据类型转换:int()、str()、float()
在Python中,数据类型转换是一项基础且重要的操作
C#基础③——类型转换(int转double、double转int、Convert)
不同数据类型间的转换,如:将int类型转换为string类型
C#中 Int32.TryParse() ConVert.ToInt32() Int32.Parse () 的区别 将字符串类型转换为数字类型
C#中 Int32.TryParse() ConVert.ToInt32() Int32.Parse () 的区别 将字符串类型转换为数字类型
89 0
C++11之正则表达式(regex_match、regex_search、regex_replace)
C++11之正则表达式(regex_match、regex_search、regex_replace)
280 0
Float.compare()和Double.compare()的使用
Float.compare()和Double.compare()的使用
142 0
Android/Java判断字符串String是否为float浮点数或double类型
Android/Java判断字符串String是否为float浮点数或double类型 Android的TextUtils的isDigitsOnly方法检测整型数据没问题,但是检测浮点和double类型可能不会返回期望的...
5192 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等