Is it faster to compare strings with Regex with IgnoreCase or with ToLower method of string?

c#, regex

Solution

Probably the second is faster, but I'd avoid both those approaches.

Better is to use the method `string.Equals` with the appropriate `StringComparison` argument:

s1.Equals(s2, StringComparison.CurrentCultureIgnoreCase)

See it working online: ideone

Problem

Given strings like these: ``` string s1 = "Abc"; string s2 = "ABC"; ``` What is faster: ``` Regex.Match(s1, s2, RegexOptions.IgnoreCase) ``` or ``` s1.ToLower() == s2.ToLower() ``` If they are the same or the one is faster then the other, so when its better to use one over the other?

Original source