如何更换口音(德国)的.NET [英] How do i replace accents (german) in .NET
本文介绍了如何更换口音(德国)的.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要替换字符串中口音的英语等值
I need to replace accents in the string to their english equivalents
例如:
一个= AE
O = OE
O =大江
U = 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#
推荐答案
如果您需要使用这个上大串,多次调用替换()
可以得到低效率很快。你可能会更好重建你的串字符逐个字符:
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) =>
{
string r;
if(map.TryGetValue(c, out r))
return sb.Append(r);
else
return sb.Append(c);
}).ToString();
这篇关于如何更换口音(德国)的.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文