Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, June 27, 2008 4:02 PM
What is the quickest way to convert RTF to TXT, without using RichtextBox?
All replies (3)
Friday, June 27, 2008 6:20 PM ✅Answered
Rtf is structured as line by line text file with the beginning of each line devoted to various formatting characters. Id you open any rtf file you can easily see when the last formatting delimiter ends. You can read any rtf file with this command:
string [] lines = Dile.ReadAllLines (pathToYourRtfFile );
// then:
foreach ( string line in lines )
{
int index = line.LatIndexOf ( @"\par" );
if ( index != -1)
{
string outLine = line.Substring (0, index);
int index2 = outLine.LastndexOf ( @"\ );
if ( index2 != -1 )
{
outLine = outLine.Substring (index2, outLine.Length - index2 );
// this is no tthe end of your trouble. There will be a format formattinc wording left. You will have to study it yourselves.
}
}
}
Not tested.
AlexB
Monday, June 30, 2008 10:00 AM ✅Answered
I quite agree with what Sheng Jiang said.
Still, you can read the following article for some example, but might not be as the "quickest way".
Converting RTF to TXT format
http://www.codeproject.com/KB/files/rtftotxtconvertor.aspx
A class library for RTF processing in C#
http://www.codeproject.com/KB/string/nrtftree.aspx.
Hope this example can inspire you some idea.
Wishes.
With one heart,with one will and with the same future. For the people,for the whole world and for the same planet.
Friday, June 27, 2008 5:52 PM
What you are asking is a world record in a minor problem. I am not sure Guinness is interested in this.
Anyway, the search of "rtf text converter C#" has some interesting results. You may need to do some benchmarking by yourself.
MSMVP VC++