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)  
else
stringBuilder.Append(c);
}
}
return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
}
Comments
Post a Comment