Output RTF special characters to Unicode

偶尔善良 提交于 2019-11-28 01:50:35

问题


I have been looking around ocn Google and Stackoverflow but haven't found what I needed, but my question seems quite simple. Anyhow;

What is the way to convert a string of RTF special characters such as "\'d3\'d6" (In this case Russian) to unicode chars or string using C#?


回答1:


any of the following should help:

  • Rich Text Format (RTF) Specification, version 1.6, Special Characters. according to this, \'d3\'d6 are hexadecimal value[s], based on the specified character set. so you could write your own processing function, like splitting the the string at \'s, converting hex to char, rejoining it, converting to unicode.
  • How to: Convert RTF to Plain Text
  • NRTFTree - A class library for RTF processing in C#
  • Questions on SO tagged rtf and c#
  • Google search "rtf c#"



回答2:


You can convert those characters:

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;
  }
}


来源:https://stackoverflow.com/questions/1310694/output-rtf-special-characters-to-unicode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!