且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何替换特殊字符与它们的等价物(诸如QUOT; A"对于"一个与QUOT)在C#?

更新时间:2022-01-19 08:41:47

您可以尝试像

var decomposed = "áéö".Normalise(NormalizationForm.FormD);
var filtered = decomposed.Where(c => char.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark);
var newString = new String(filtered.ToArray());

这口音分解从文本,过滤它们,并创建一个新的字符串。结合变音符号都在非间距标记的Unicode 的类别。

This decomposes accents from the text, filters them and creates a new string. Combining diacritics are in the Non spacing mark unicode category.