Remove Diacritics Using C#

Remove Diacritics Using C#


public static string NormalizeString(string text)
{
    string normalStr = text.Normalize(NormalizationForm.FormD);
    var stringBuilder = new StringBuilder();

     foreach (var c in normalStr)
     {
          var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
          if (unicodeCategory != UnicodeCategory.NonSpacingMark)
          {
             if (char.IsWhiteSpace(c))
                 stringBuilder.Append((char)32); // Removed  (160) &#32
             else
                 stringBuilder.Append(c);
           }
      }
            return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
}

Comments

Popular posts from this blog

Certificate Pinning in Windows 10 UWP app

Configure Apache and php