Panowie problemem nie jest zamiana znaków na inne tylko problemem jest to, że po StringReplace w RichEdit będzie pozmieniane formatowanie, a autor chce je zachować. Znalazłem kod na: http://delphi.about.com/cs/adptips2003/a/bltip0803_2.htm ale on jest nieprzewidziany do zamieniania na pusty tekst, bo wtedy w oryginalnym kodzie pętla trwa w nieskonczoność. Poprawiłem i z moich pobieżnych testów wynika, ze jest ok, ale jakby coś dalej nie działało to niech pytający już kombinuje dalej sam.
procedure RichEditRearchAndReplace(RichEdit : TRichEdit; InSearch, InReplace : string);
var
X, ToEnd : integer;
oldCursor : TCursor;
begin
oldCursor := Screen.Cursor;
Screen.Cursor := crHourglass;
with RichEdit do
begin
X := 0;
ToEnd := length(Text);
X := FindText(inSearch, X, ToEnd, []);
if InReplace <> '' then
begin
while X <> -1 do
begin
SelStart := X;
SelLength := length(inSearch);
SelText := InReplace;
X := FindText(inSearch, X + length(InReplace), ToEnd, []);
end;
end
else
begin
repeat
SelStart := X;
SelLength := length(inSearch);
SelText := InReplace;
X := FindText(inSearch, X + Length(InReplace), ToEnd, []);
until X < ToEnd;
end;
end;
Screen.Cursor := oldCursor;
end;
Przykład użycia dla zamiany Windowsowych znaków końca lini na "pusty" tekst:
RichEditRearchAndReplace(RichEdit1, #13#10, '');