可能重复:
How to convert a Unicode character to its ASCII equivalent
How do I remove diacritics (accents) from a string in .NET?
Convert Unicode char to closest (most similar) char in ASCII (.NET)
我会接受不一定是英语的名字,需要将它们转换成基本的名字。即音译é到e
我不必担心将日语转换成英文字母。
有没有办法做到这一点?
由于
答案:
public void ConvertDiacritic()
{
nameInFull = nameInFull.Normalize(NormalizationForm.FormD);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < nameInFull.Length; i++)
{
UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(nameInFull[i]);
if (uc != UnicodeCategory.NonSpacingMark)
{
sb.Append(nameInFull[i]);
}
}
nameInFull = sb.ToString().Normalize(NormalizationForm.FormC);
}