C#正则表达式之字符替换

时间:2023-03-09 04:57:19
C#正则表达式之字符替换

C#正则表达式之字符替换

string strTest= "www.BaiDu.com",strRst="";

            //忽略大小写,将strTest中的BaiDu替换为baidu
Regex myRegex = new Regex("baidu",RegexOptions.IgnoreCase);
strRst=myRegex.Replace(strTest,"baidu"); Console.WriteLine("\n替换前的字符串为:"+strTest);
Console.WriteLine("\n替换后的字符串为:"+strRst);
Console.WriteLine(); Console.WriteLine(The_Day.getTheDay()+" By yxHuang!..."); //暂停,用于查看效果
Console.Read();