Is there a way to do case insensitive 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With