我需要将字符串中的重音符号替换为其对应的英文
I need to replace accents in the string to their english equivalents
例如
ä = ae
ö = oe
Ö = Oe
ü = ue
我知道从字符串中去除它们,但我不知道替换.
I know to strip of them from string but i was unaware about replacement.
如果您有任何建议,请告诉我.我正在用 C# 编码
Please let me know if you have some suggestions. I am coding in C#
如果您需要在较大的字符串上使用它,多次调用 Replace() 会很快变得效率低下.您最好逐个字符地重建字符串:
If you need to use this on larger strings, multiple calls to Replace() can get inefficient pretty quickly. You may be better off rebuilding your string character-by-character:
var map = new Dictionary<char, string>() {
{ 'ä', "ae" },
{ 'ö', "oe" },
{ 'ü', "ue" },
{ 'Ä', "Ae" },
{ 'Ö', "Oe" },
{ 'Ü', "Ue" },
{ 'ß', "ss" }
};
var res = germanText.Aggregate(
new StringBuilder(),
(sb, c) => map.TryGetValue(c, out var r) ? sb.Append(r) : sb.Append(c)
).ToString();
这篇关于我如何在 .NET 中替换口音(德语)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
string1 >= string2 未在 Linq to SQL 中实现,有什string1 gt;= string2 not implemented in Linq to SQL, any workaround?(string1 gt;= string2 未在 Linq to SQL 中实现,有什么解决方法吗?)
如何在条件下使用 RemoveAll 删除列表中的多个项目How to Remove multiple items in List using RemoveAll on condition?(如何在条件下使用 RemoveAll 删除列表中的多个项目?)
转换表达式树Convert Expression trees(转换表达式树)
当 IDENTITY_INSERT 设置为 OFF 时,无法为表“ClientCannot insert explicit value for identity column in table #39;ClientDetails#39; when IDENTITY_INSERT is set to OFF(当 IDENTITY_INSERT 设置为 OFF 时,
Linq 独特的 &最大限度Linq distinct amp; max(Linq 独特的 amp;最大限度)
使用 LinqPad 将字符串转换为 GuidCast string as Guid using LinqPad(使用 LinqPad 将字符串转换为 Guid)