不使用C#中的正则表达式进行不区分大小写的替换?
有没有办法在不使用C#中的正则表达式的情况下对字符串进行不区分大小写的替换?
这样的事情
string x = "Hello"; x = x.Replace("hello", "hello world");
你可以尝试类似的东西
string str = "Hello"; string replace = "hello"; string replaceWith = "hello world"; int i = str.IndexOf(replace, StringComparison.OrdinalIgnoreCase); int len = replace.Length; str = str.Replace(str.Substring(i, len), replaceWith);
看看String.IndexOf方法(String,StringComparison)
以下链接可能会有所帮助。
是否有不区分大小写的string.Replace的替代方法?
http://www.codeproject.com/KB/string/fastestcscaseinsstringrep.aspx
http://www.west-wind.com/weblog/posts/60355.aspx
Microsoft.VisualBasic
程序集中还有Strings.Replace函数。