How to compare strings with case insensitive and accent insensitive
Alright this is done easily at SQL server
However I would like to do the same at C# .NET
You can use string.Compare
with the overload which takes the proper CultureInfo
and CompareOptions
:
string.Compare(s1, s2, CultureInfo.CurrentCulture, CompareOptions.IgnoreNonSpace |
CompareOptions.IgnoreCase);
Edit:
As for your question on CultureInfo
, from MSDN:
The comparison uses the culture parameter to obtain culture-specific information, such as casing rules and the alphabetical order of individual characters. For example, a particular culture could specify that certain combinations of characters be treated as a single character, that uppercase and lowercase characters be compared in a particular way, or that the sort order of a character depends on the characters that precede or follow it.