2006. október 9., hétfő

How to detect a CR / LF in a TRichEdit


Problem/Question/Abstract:

I need to determine where there are CR/LF's in a TRichEdit. Here's the problem. I need to use the TRichEdit to take pretty much just plain text. I am using the TRichEdit instead of the TMemo because it handles end-of-line spaces much better. When I save the text, I need to save it in a proprietary text format. So when I encounter a CRLF, I need to place a "/p" combination at the end of the text line.

Answer:

procedure SaveTextWithParagraphMarkers(const filename, Text, marker: string);
var
  fs: TFilestream;
  S: string;
begin
  S := Stringreplace(text, #13#10, marker, [srReplaceAll]);
  fs := TFilestream.Create(filename, fmCreate);
  try
    fs.WriteBuffer(S[1], Length(S));
  finally
    fs.Free
  end;
end;

SaveTextWithParagraphMakers(filename, richedit1.text, '/p'#13#10);

Nincsenek megjegyzések:

Megjegyzés küldése