locked
RTF to plain text RRS feed

  • Question

  • Hi :

    I have text in RTF format like {<rtf >/par This is text...

    I have to convert it into plain text like This is text

    I have searched on net but I want to do it without using RichTextBox control...

    Is there any way to convert it without using RichTextBox?

    Thanks

    Wednesday, July 4, 2012 6:02 AM

Answers

  • Hello Shailesh,

    I have create below function for you. Just pass your text in RTF format. This will return you plain text.

    private String GetPlainTextFromRTF(String rtf)
    {
        RichTextBox rtb = new RichTextBox();
        rtb.Rtf = rtf;
        return rtb.Text;
    }

    I hope this helps.

    Please mark this post as answer if it solved your problem. Happy Programming!

    • Proposed as answer by Ellen Ramcke Wednesday, July 4, 2012 11:20 AM
    • Marked as answer by Mike Feng Thursday, July 19, 2012 2:48 AM
    Wednesday, July 4, 2012 7:13 AM
  • Why do you consider RichTextBox as a control? In my point of view it is just another class. If I display it on the form, the it is different story. So, I don't see any harm in using RichTextBox class.

    If you really don't want to use RichTextBox class, then as MukiJames said, use RtfDom Parsing - but that will add more complexity.


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Proposed as answer by Cor Ligthert Thursday, July 5, 2012 6:00 AM
    • Marked as answer by Mike Feng Thursday, July 19, 2012 2:48 AM
    Wednesday, July 4, 2012 9:04 AM

All replies

  • Hi,

    There are free RTF parsers, you can try them. For example:

    RTF DOM Parser

    NRTFTree

    Wednesday, July 4, 2012 7:07 AM
  • Hello Shailesh,

    I have create below function for you. Just pass your text in RTF format. This will return you plain text.

    private String GetPlainTextFromRTF(String rtf)
    {
        RichTextBox rtb = new RichTextBox();
        rtb.Rtf = rtf;
        return rtb.Text;
    }

    I hope this helps.

    Please mark this post as answer if it solved your problem. Happy Programming!

    • Proposed as answer by Ellen Ramcke Wednesday, July 4, 2012 11:20 AM
    • Marked as answer by Mike Feng Thursday, July 19, 2012 2:48 AM
    Wednesday, July 4, 2012 7:13 AM
  • Thanks for your help Adavesh

    But I want to do it without using RichTextBox..

    I dont want to use any UI control for this conversion.

    Is there any other way?

    Wednesday, July 4, 2012 8:56 AM
  • Why do you consider RichTextBox as a control? In my point of view it is just another class. If I display it on the form, the it is different story. So, I don't see any harm in using RichTextBox class.

    If you really don't want to use RichTextBox class, then as MukiJames said, use RtfDom Parsing - but that will add more complexity.


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Proposed as answer by Cor Ligthert Thursday, July 5, 2012 6:00 AM
    • Marked as answer by Mike Feng Thursday, July 19, 2012 2:48 AM
    Wednesday, July 4, 2012 9:04 AM
  • Thanks for help..

    I can use it as class without importing namespace in my code..

    System.Windows.Forms.RichTextBox...

    Wednesday, July 4, 2012 11:34 AM
  • Yeah... anyway you can use it. It doesn't matter.

    Please mark this post as answer if it solved your problem. Happy Programming!

    Wednesday, July 4, 2012 11:48 AM