时间紧,任务重,RTF转string!

powerchuangwai 2011-12-05 11:12:02
从ORACLE数据库中提取的数据,为RTF格式,大概格式如下:
\'a3 \'f1 \'35 \'d7 par

如何将其转为string格式,主要是转为汉字。

有网友说用RichTextBox可以转,我没用过。

请指点!
...全文
79 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
铜臂阿铁木 2011-12-05
  • 打赏
  • 举报
回复
如果你只想解析一部分,
用这个包裹住


{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset134 Arial;}}

你的内容
}


{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset134 Arial;}}
这部分需要你从你的数据库里面找到头来确定,否则解析不出来。
铜臂阿铁木 2011-12-05
  • 打赏
  • 举报
回复

System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();
rtBox.Rtf = 你的数据,必须完整;
string plainText = rtBox.Text;


你用这部分就够了。
铜臂阿铁木 2011-12-05
  • 打赏
  • 举报
回复

class ConvertFromRTF
{
static void Main()
{

string path = @"test.rtf";

//Create the RichTextBox. (Requires a reference to System.Windows.Forms.dll.)
System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox();

// Get the contents of the RTF file. Note that when it is
// stored in the string, it is encoded as UTF-16.
string s = System.IO.File.ReadAllText(path);

// Display the RTF text.
System.Windows.Forms.MessageBox.Show(s);

// Convert the RTF to plain text.
rtBox.Rtf = s;
string plainText = rtBox.Text;

// Display plain text output in MessageBox because console
// cannot display Greek letters.
System.Windows.Forms.MessageBox.Show(plainText);

// Output plain text to file, encoded as UTF-8.
System.IO.File.WriteAllText(@"output.txt", plainText);
}
}




来自MSDN
powerchuangwai 2011-12-05
  • 打赏
  • 举报
回复
感谢!

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧