Case insensitive replace without using regular expression in C#?
Is there a way to do case insensi开发者_高级运维tive replace on a string without using regular expression in C#?
something like this
string x = "Hello";
x = x.Replace("hello", "hello world");
You can try something like
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);
Have a look at String.IndexOf Method (String, StringComparison)
The following links may be of help.
Is there an alternative to string.Replace that is case-insensitive?
http://www.codeproject.com/KB/string/fastestcscaseinsstringrep.aspx
http://www.west-wind.com/weblog/posts/60355.aspx
There is also the Strings.Replace function in the Microsoft.VisualBasic
assembly.
精彩评论