Let\'s say I have 2 strings.First string is x = \"abc\" and the second one is y = \"ABC\".When I write in c# following code:
if(x == y)
or
As Pleun wrote, or you can
StringComparer.CurrentCultureIgnoreCase.Equals(a, b)
Note that we are using the CurrentCulture
ordering method. Sometimes you'll have to use different ordering methods (every language orders the letters in a different way)
If you are sure that you are only ordering ASCII characters then
StringComparer.OrdinalIgnoreCase.Equals(a, b)
is a little faster (or in general methods where you can select the OrdinalIgnoreCase
)
In general converting ToUpper()
or ToLower()
two strings to compare them is wrong (and slow, because you have to convert them fully before comparing them, while perhaps they are different in the first character)... Wrong because in Turkish there are four i
http://codeblog.jonskeet.uk/2009/11/02/omg-ponies-aka-humanity-epic-fail/