Remove diacritics (accents) from a string / retirer accent – c#

1
2
3
4
5
6
7
8
9
public static string RemoveDiacritics(this string text)
{
    if (string.IsNullOrWhiteSpace(text))
        return text;

    text = text.Normalize(NormalizationForm.FormD);
    var chars = text.Where(c => CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark).ToArray();
    return new string(chars).Normalize(NormalizationForm.FormC);
}
Please follow and like us:
Catégoriesc#

Laisser un commentaire