如何替换特殊字符与它们的等价物(诸如QUOT; A"对于"一个与QUOT)在C#? [英] How to replace special characters with their equivalent (such as " á " for " a") in C#?

查看:286
本文介绍了如何替换特殊字符与它们的等价物(诸如QUOT; A"对于"一个与QUOT)在C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要得到葡萄牙文本内容出一个Excel文件,并创建将是由不支持的字符,如C,A,E的应用程序中使用的XML和其他。我不能只是删除的人物,但他们相当于取代他们(C,A,E,例如)。

I need to get the Portuguese text content out of an Excel file and create an xml which is going to be used by an application that doesn't support characters such as "ç", "á", "é", and others. And I can't just remove the characters, but replace them with their equivalent ("c", "a", "e", for example).

我想有一个更好的办法做到这一点比逐个检查每个字符,并与同行进行更换。如何做到这一点有什么建议?

I assume there's a better way to do it than check each character individually and replace it with their counterparts. Any suggestions on how to do it?

推荐答案

您可以尝试像

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.

这篇关于如何替换特殊字符与它们的等价物(诸如QUOT; A"对于"一个与QUOT)在C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆