我在Google和Stackoverflow上搜索了很久,但是没有找到我需要的答案,不过我的问题似乎很简单。无论如何;
使用C#将RTF特殊字符的字符串(例如"\ 'd3' d6"(在此情况下为俄语))转换为Unicode字符或字符串的方法是什么?
以下任何一种方案都可能有所帮助:
\'d3\'d6
是基于指定字符集的16进制值。因此,您可以编写自己的处理函数,例如在\'
处拆分字符串,将16进制转换为字符,重新连接它,再将其转换为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;
}
}