domingo, 31 de maio de 2009

Dicas Delphi - Procurando e Substituindo string num campo memo

Procedure FindReplace(const Enc, subs: String; Var Texto: TMemo);
Var
i, Posicao: Integer;
Linha: string;
Begin
For i:= 0 to Texto.Lines.count - 1 do
begin
Linha := Texto. Lines[i];
Repeat
Posicao:=Pos(Enc,Linha);
If Posicao > 0 then
Begin
Delete(Linha,Posicao,Length(Enc));
Insert(Subs,Linha,Posicao);
Texto.Lines[i]:=Linha;
end;
until Posicao = 0;
end;
end;

// Utilize a função assim:

Procedure TForm1.Button1Click (Sender: TObject);
Begin
FindReplace(Edit1.Text,Edit2.Text, Memo1);
end;

Nenhum comentário: