问题
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