Why doesn't Đ get flattened to D when Removing Accents/Diacritics

后端 未结 5 1884
你的背包
你的背包 2021-01-04 01:37

I\'m using this method to remove accents from my strings:

static string RemoveAccents(string input)
{
    string normalized = input.Normalize(NormalizationFo         


        
5条回答
  •  执笔经年
    2021-01-04 01:48

    this should work

        private static String RemoveDiacritics(string text)
        {
            String normalized = text.Normalize(NormalizationForm.FormD);
            StringBuilder sb = new StringBuilder();
    
            for (int i = 0; i < normalized.Length; i++)
            {
                Char c = normalized[i];
                if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
                    sb.Append(c);
            }
    
            return sb.ToString();
        }
    

提交回复
热议问题