function ReplaceTextA(var SText: string; TextFind, TextReplace: string);string;
var
S: string;
SLen: LongInt;
SPos: Integer;
begin
S := '';
SLen := Length(TextFind);
SPos := Pos(TextFind, SText);
while SPos > 0 do
begin
S := S + Copy(SText, 1, SPos - 1) + TextReplace;
Delete(SText, 1, SPos + SLen - 1);
SPos := Pos(TextFind, SText);
end;
S := S + SText;
SText := S;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
begin
s:='x pp wy1 oop pp';
ReplaceTextA(s,'pp','王');
memo1.Text:=s;
end;