问题描述
我用这个方法来从我删除字符串的口音:
I'm using this method to remove accents from my strings:
static string RemoveAccents(string input)
{
string normalized = input.Normalize(NormalizationForm.FormKD);
StringBuilder builder = new StringBuilder();
foreach (char c in normalized)
{
if (char.GetUnicodeCategory(c) !=
UnicodeCategory.NonSpacingMark)
{
builder.Append(c);
}
}
return builder.ToString();
}
但这种方法留下的DJ DJ兼并不将其更改为D,即使d为它的基字符。你可以用这个输入字符串试试æøåáâăäĺćçčéęëěíîďđńňóôőöřůúűüýţ
but this method leaves đ as đ and doesn't change it to d, even though d is its base char.you can try it with this input string "æøåáâăäĺćçčéęëěíîďđńňóôőöřůúűüýţ"
有什么特别的信DJ的?
What's so special in letter đ?
推荐答案
对于答案的为什么的它不工作是,声明说:d为它的基炭是假的。 U + 0111(拉丁小写字母中风D)具有统一code类字母,小写,并没有分解的映射(即,它不分解到D,其次是一个组合标志)。
The answer for why it doesn't work is that the statement that "d is its base char" is false. U+0111 (LATIN SMALL LETTER D WITH STROKE) has Unicode category "Letter, Lowercase" and has no decomposition mapping (i.e., it doesn't decompose to "d" followed by a combining mark).
DJ.Normalize(NormalizationForm.FormD)
只返回DJ
,这是不剥离出来由环路,因为它不是一个非间距标记
"đ".Normalize(NormalizationForm.FormD)
simply returns "đ"
, which is not stripped out by the loop because it is not a non-spacing mark.
有一个类似的问题将存在于O等字母而统一code提供不分解的映射。 (如果你想找到最佳的ASCII字符重新present一个统一code字母,这种做法是行不通的在所有的西里尔文,希腊文,中国或其它非拉丁字母;你还会遇到一些问题,如果你想音译SS到SS,例如使用一个图书馆一样的可能会有所帮助。)
A similar issue will exist for "ø" and other letters for which Unicode provides no decomposition mapping. (And if you're trying to find the "best" ASCII character to represent a Unicode letter, this approach won't work at all for Cyrillic, Greek, Chinese or other non-Latin alphabets; you'll also run into problems if you wanted to transliterate "ß" into "ss", for example. Using a library like UnidecodeSharp may help.)
这篇关于为什么不删除口音时/变音符号Đ得到夷为平地到D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!