我一直在寻找 ocn Google 和 Stackoverflow,但没有找到我需要的东西,但我的问题似乎很简单。无论如何;
使用 C# 将一串 RTF 特殊字符(例如“\'d3\'d6”(在本例中为俄语))转换为 unicode 字符或字符串的方法是什么?
以下任何一项都应该有帮助:
\'d3\'d6
是十六进制值[s],基于指定的字符集。所以你可以编写自己的处理函数,比如在\'
s 处拆分字符串,将十六进制转换为字符,重新加入它,转换为 unicode。您可以转换这些字符:
int findUTF = -1;
bool continueUTFSearch = true;
do
{
findUTF = HTMLText.IndexOf(@"\'", findUTF + 1);
if (findUTF != -1)
{
string replacedString = HTMLText.Substring(findUTF, 4);
string esacpeddString = replacedString.Substring(2);
int esacpeddCharValue = Convert.ToInt16(esacpeddString, 16);
char esacpeddChar = Convert.ToChar(esacpeddCharValue);
esacpeddString = esacpeddChar.ToString();
HTMLText = HTMLText.Replace(replacedString, esacpeddString);
findUTF = -1;
}
else
{
continueUTFSearch = false;
}
}