Lucene.NET tutorials and examples

How to extract text from RTF files

How to extract text from RTF files in .NET using RichTextBox control.
Tags: c# parsing rtf

The easiest way to parse RTF is to use the RichTextBox component from System.Windows.Forms namespace (requires a reference to System.Windows.Forms assembly):

/// <summary>
/// Parses RTF document.
/// </summary>
/// <param name="rtf">RTF document source</param>
/// <returns>Plain text</returns>
private static string parseRtf(string rtf)
{
	RichTextBox rtb = new RichTextBox();
	rtb.Rtf = rtf;
	return rtb.Text;
}