从文本文件中删除重音符号 [英] Remove accents from a text file
本文介绍了从文本文件中删除重音符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在从文本文件程序中删除重音符号时遇到问题,用变音符号将字符替换为?这是我的代码:
I have issues with removing accents from a text file program replaces characters with diacritics to ? Here is my code:
private void button3_Click(object sender, EventArgs e)
{
if (radioButton3.Checked)
{
byte[] tmp;
tmp = System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(richTextBox1.Text);
richTextBox2.Text = System.Text.Encoding.UTF8.GetString(tmp);
}
}
推荐答案
richTextBox1.Text = "včľťšľžšžščýščýťčáčáčťáčáťýčťž";
string text1 = richTextBox1.Text.Normalize(NormalizationForm.FormD);
string pattern = @"\p{M}";
string text2 = Regex.Replace(text1, pattern, "�");
richTextBox2.Text = text2;
首先规范化字符串.
然后用正则表达式替换所有变音符号.模式 \ p {M}
是 Unicode类别-所有变音符号.
First normalize the string.
Then with a regular expression replace all diacritics. Pattern \p{M}
is Unicode Category - All diacritic marks.
这篇关于从文本文件中删除重音符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文