[HowTo] LINQ filter : Ignore accented letters (Diacritics) in string comparison ?

Here is a small extension method that will do the job (Warning : do not use for Linq To Sql):

public static string RemoveDiacritics(this string text)
  string formD = text.Normalize(NormalizationForm.FormD);
  StringBuilder sb = new StringBuilder();

  foreach (char ch in formD)
    UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(ch);
    if (uc != UnicodeCategory.NonSpacingMark)

  return sb.ToString().Normalize(NormalizationForm.FormC);

Anyway, this is fine if you are just iterating over a collection in C#, but if you are using LINQ to SQL it is preferable to avoid non-standard methods (including extension methods) in your LINQ query. This is because your code cannot be converted into valid SQL and hence run on SQL Server with all its lovely performance optimization.

External links :

Leave a Reply