rtf编码问题,需要达人回答。
中文转换成rtf编码。
rtf编码不支持中文,中文需要类似如下转换:
文档->\'ce\'c4\'b5\'b5
谁有编码表?或者现成的转换程序(源码)。
问题点数:0、回复次数:4Top
1 楼zju3020912063()回复于 2005-04-03 10:16:27 得分 0
不知道的也帮忙顶下。谢谢,没分了~Top
2 楼BigIdiot628(大笨蛋,谁叫你不努力!)回复于 2005-04-03 11:07:10 得分 0
帮你顶Top
3 楼lucbesson(女娃哈哈)回复于 2005-04-05 21:39:22 得分 0
RTF格式分析源码,地址在这里:http://itextsharp.sourceforge.net/
RTF是ASCII的纯文本格式,中文等字符必须转换成ASCII表示,如“中”字在.rtf文件中显示“\'d6\'d0“(中文双字节),下面是我写的一段将字符串转换成RTF编码的方法。
/**//// <summary>
/// 将字符串转换成RTF编码
/// </summary>
/// <param name="str">字符串</param>
/// <returns>将字符串转换成纯ASCII的编码</returns>
public static string StrToRtf(string str)
{
int length = str.Length;
int z = (int)'z';
StringBuilder ret = new StringBuilder(length);
for(int i = 0; i < length; i++)
{
char ch = str[i];
if(ch == '\\')
{
ret.Append("\\\\");
}
else if(ch == '\n')
{
ret.Append("\\par ");
}
else if(((int)ch) > z)
{
Encoding targetEncoding;
byte[] encodedChars;
// Gets the encoding for the specified code page.
targetEncoding = Encoding.Default ;
// Gets the byte representation of the specified string.
encodedChars = targetEncoding.GetBytes(str[i].ToString());
for(int j=0; i<encodedChars.Length;j++)
{
string st = encodedChars[j].ToString();
ret.Append("\\'").Append(int.Parse(st).ToString("X"));
}
}
else
{
ret.Append(ch);
}
}
return ret.ToString();
}
Top
4 楼lucbesson(女娃哈哈)回复于 2005-04-05 21:39:58 得分 0
曾经在一个blog上看到的
忘了地址啦Top




