Since there is no case insensitive string.Contains()
(yet a case insensitive version of string.Equals()
exists which baffles me, but I digress) in .NET, What is the performance differences between using RegEx.IsMatch()
vs. using String.ToUpper().Contains()
?
Example:
string testString = "tHiSISaSTRINGwiThInconSISteNTcaPITaLIZATion";
bool containsString = RegEx.IsMatch(testString, "string", RegexOptions.IgnoreCase);
bool containsStringRegEx = testString.ToUpper().Contains("STRING");
I've always heard that string.ToUpper()
is a very expensive call so I shy away from using it when I want to do string.Contains()
comparisons, but how does RegEx.IsMatch()
compare in terms of performance?
Is there a more efficient approach for doing such comparisons?