string sentence = "We know it contains 'camel' word.";
// Camel can be in different cases:
string s1 = "CAMEL";
string s2 = "CaMEL";
string s3 = "CAMeL";
// ...
string s4 = "Camel";
// ...
string s5 = "camel";
How to replace ‘camel’ in sentence with ‘horse’ despite of string.Replace doesn’t support ignoreCase on left string?
Use a regular expression:
Of course, this will also match words containing camel, but it’s not clear if you want that or not.
If you need exact matches you can use a custom MatchEvaluator.
Used with the previous example to wrap the match in a span as: