I have the below method where I need to check for some certain strings which could be in any case and then remove them. Just wondered if there was a better performing way?
private void MyMethod(string Filter)
{
//need to remove <Filter> and </Filter> case in-sensitive
var result = Filter.ToLower().Replace("<filter>","");
result = Filter.ToLower().Replace("</filter>,"");
...........................
}
One problem with that approach is that it will turn the entire string into lower case, not just make a case insensetive replace.
You can use a regular expression to do a case insensetive match:
Another alternative is to use the
IndexOfmethod to locate the strings, as it can do a case insensetive search: