Link to home
Start Free TrialLog in
Avatar of Spokyx
Spokyx

asked on

Remove RichText formatting

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.
ASKER CERTIFIED SOLUTION
Avatar of geobul
geobul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of geobul
geobul

Forgot to say: I presume that you already have a rtf file loaded in the Richedit1.
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
Avatar of Spokyx

ASKER

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.
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.