?
Solved

Remove RichText formatting

Posted on 2003-03-06
5
Medium Priority
?
303 Views
Last Modified: 2013-11-22
I need an efficient way to remove all RichText formatting from a RTF file (in memory). Something like loading a RTF file into a TStrings and then remove all the \par stuff, but leaving the file as plain text (main content untouched). The fastest it goes, the better.
0
Comment
Question by:Spokyx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 100 total points
ID: 8078534
Hi,

Try this:

procedure TForm1.Button1Click(Sender: TObject);
var
  ms: TMemoryStream;
begin
  ms := TMemoryStream.Create;
  try
    RichEdit1.PlainText := true;
    RichEdit1.Lines.SaveToStream(ms);
    ms.Position := 0;
    RichEdit1.Lines.Clear;
    RichEdit1.Lines.LoadFromStream(ms);
    RichEdit1.PlainText := false;
  finally
    ms.Free;
  end;
end;

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 8078554
Forgot to say: I presume that you already have a rtf file loaded in the Richedit1.
0
 
LVL 17

Expert Comment

by:geobul
ID: 8078596
If you want to load an rtf file from disk here is another version:

procedure LoadRtf(re: TRichEdit; filename: string);
var
  ms: TMemoryStream;
begin
  ms := TMemoryStream.Create;
  try
    re.Lines.BeginUpdate;
    try
      re.Lines.LoadFromFile(filename);
      re.PlainText := true;
      re.Lines.SaveToStream(ms);
      ms.Position := 0;
      re.Lines.Clear;
      re.Lines.LoadFromStream(ms);
      re.PlainText := false;
    finally
      re.Lines.EndUpdate;
    end;
  finally
    ms.Free;
  end;
end;

// usage:
procedure TForm1.Button1Click(Sender: TObject);
begin
  LoadRtf(RichEdit1,'c:\program files\Borland\Delphi5\Demos\RichEdit\overview.rtf');
end;

Regards, Geo
0
 

Author Comment

by:Spokyx
ID: 8083059
No, no. You didn't understand me. I want to remove all RTF formatting AFTER the file was loaded into TStrings (thus, in memory). The code is in a DLL so I don't want to include ComCtrls or whatever, I don't want to include the RichEdit component.

To explain myself better, imagine that I load the whole RTF file into a huge String, and then want to parse it removing all RTF formatting to leave it's content untouched.
0
 

Expert Comment

by:CleanupPing
ID: 9316909
Spokyx:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question