如何在 .NET 中替换重音符号(德语)
我需要将字符串中的重音符号替换为对应的英文重音符号
,例如
ä = ae
ö = oe
Ö = Oe
ü = ue
我知道从字符串中删除它们,但我不知道替换。
如果您有任何建议,请告诉我。 我正在用 C# 编码
I need to replace accents in the string to their english equivalents
for example
ä = ae
ö = oe
Ö = Oe
ü = ue
I know to strip of them from string but i was unaware about replacement.
Please let me know if you have some suggestions. I am coding in C#
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您需要在较大的字符串上使用此功能,则多次调用
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:是否只想将德语变音符号映射到两个字母(非变音符号)变体? 干得好; 未经测试,但它可以处理所有德语元音变音。
Do just want a mapping of german umlauts to the two-letter (non-umlaut) variant? Here you go; untested, but it handles all german umlauts.
我想不出任何自动方法来执行此操作,因此我相信您必须手动执行此操作。
IE。
有多少个字符? 所有元音,大写和小写,那么,10? 工作量不应该太大。
I can't think of any automatic way to do this, so I believe you'd have to do it manually.
ie.
How many characters are there? All vowels, in upper and lower case, so, 10? Shouldn't be too much of a job.
使用 string.Replace 怎么样:(
好吧,不是真正的德语单词,但我无法抗拒)
你可以像这样链接调用 Replace
How about using string.Replace:
(okay, not a real German word, but I couldn't resist)
You can chain calls to Replace like this
此类删除变音符号(é、ì、è 等),并用其等效项“ae (ä)”、“oe (ö)”、“ue (ü)”和“ss”替换变音符号和德语“ß” (ß)”。
用法:
在“Übermut”情况下有一个小错误,用“UE”代替“Ue”替换“Ü”。但这很容易修复。享受吧:)
This class removes diacritic characters (é, ì, è, etc.) and replaces umlauts and the German "ß" with their equivalents "ae (ä)", "oe (ö)", "ue (ü)" and "ss (ß)".
Usage:
There is a minor bug in the "Übermut" case replacing "Ü" with "UE" instead of Ue". But this can be easily fixed. Enjoy :)