procedure Tmainfm.Button1Click(Sender: TObject);
var SelPos: Integer;
s : string;//查找的字符串
ss;//替代的string
begin
with TReplaceDialog(Sender) do
begin
s := #$D#$A;
ss := ' ';
SelPos := Pos(s, Memo1.Lines.Text);
if SelPos > 0 then
begin
Memo1.SelStart := SelPos - 1;
Memo1.SelLength := Length(s);
Memo1.SelText := ss;
end
else showmessage('No found!');
end;
end;
function ReplaceStr(const S, Srch, Replace: string): string;
var
I: Integer;
Source: string;
begin
Source := S;
Result := '';
repeat
I := Pos(Srch, Source);
if I > 0 then begin
Result := Result + Copy(Source, 1, I - 1) + Replace;
Source := Copy(Source, I + Length(Srch), MaxInt);
end
else Result := Result + Source;
until I <= 0;
end;
var
SourceStr:string;
Post:Integer;
begin
SourceStr:='this is test '+#13#10+'next line';
Post:=Pos(#$D#$A,SourceStr);
while Post>0 do
begin
Delete(sourceStr,Post,2);
Insert(' ',SourceStr,Post);
Post:=Pos(#$D#$A,SourceStr);
end;
end;