将RTF转换为纯文本 [英] Convert RTF To Plain Text

查看:106
本文介绍了将RTF转换为纯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
我想知道如何使用C#将rtf内容转换为文本。我试过这个但是没有用。

Hi I want to know how to convert rtf content to text using C#. I've tried this but its not working.

string s = System.IO.File.ReadAllText(path);
 RichTextBox rtb = new RichTextBox();
          rtb.Rtf = s;
          return rtb.Text;










Rtf Content:
{\rtf1\deff0{\fonttbl{\f0 Times New Roman;}}{\colortbl\red0\green0\blue0 ;\red0\green0\blue255 ;}{\*\listoverridetable}{\stylesheet {\ql Normal;}{\*\cs1 Default Paragraph Font;}{\*\cs2\sbasedon1 Line Number;}{\*\cs3\ul\cf1 Hyperlink;}{\*\ts4\tsrowd\ql\trautofit1\tscellpaddfl3\tscellpaddl108\tscellpaddfr3\tscellpaddr108\tsvertalt\cltxlrtb Normal Table;}{\*\ts5\tsrowd\sbasedon4\ql\trbrdrt\brdrs\brdrw10\trbrdrl\brdrs\brdrw10\trbrdrb\brdrs\brdrw10\trbrdrr\brdrs\brdrw10\trautofit1\tscellpaddfl3\tscellpaddl108\tscellpaddfr3\tscellpaddr108\tsvertalt\cltxlrtb Table Simple 1;}}\nouicompat\splytwnine\htmautsp\sectd\pard\plain\ql{\cf0 Test OutPut}\par}

Expected Text: Test Output

But I'm getting Output Code:
{\rtf1\deff0{\fonttbl{\f0 Times New Roman;}}{\colortbl\red0\green0\blue0 ;\red0\green0\blue255 ;}{\*\listoverridetable}{\stylesheet {\ql\cf0 Normal;}{\*\cs1\cf0 Default Paragraph Font;}{\*\cs2\sbasedon1\cf0 Line Number;}{\*\cs3\ul\cf1 Hyperlink;}}\sectd\pard\plain\ql\par}







已添加代码块[/ Edit]




Code block added[/Edit]

推荐答案

这必须有效,它与上记录的相同MSDN [ ^ ] ...你为什么这么想没有正确转换?
This must work, it is the same as documented on the MSDN[^]... Why do you think it is not converted correctly?






我认为(但我不确定)这是编码问题。

试试这个:

Hi,

I think (but I'm not sure) it's an encoding problem.
Try this:
string s = System.IO.File.ReadAllText(path, Encoding.UTF8);
 RichTextBox rtb = new RichTextBox();
          rtb.Rtf = s;
          return rtb.Text;



希望这会有所帮助。


Hope this helps.


这篇关于将RTF转换为纯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆