Case insensitive replaced without using regex in C #?

Is there a way of case insensitivity to replace a string without using a regex in C #?

something like that

string x = "Hello"; x = x.Replace("hello", "hello world"); 
+6
source share
2 answers

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); 

See String.IndexOf Method (String, StringComparison)

+6
source share

The following links may help.

Is there an alternative to string.Replace that is not case sensitive?

http://www.codeproject.com/KB/string/fastestcscaseinsstringrep.aspx

http://www.west-wind.com/weblog/posts/60355.aspx

There is a Strings.Replace function in the Microsoft.VisualBasic assembly.

+1
source share

All Articles