给个自己写的:
C++版:
AnsiString __fastcall ReplaceStr(AnsiString text, AnsiString src, AnsiString dst)
{
AnsiString tmp, res;
tmp = res = text;
int pos = tmp.Pos(src);
while( pos > 0 )
{
res = tmp.SubString(1, pos - 1);
res += dst;
pos += StrLen(dst);
res += tmp.SubString(pos, tmp.Length() - pos + 1);
tmp = res;
pos = tmp.Pos(atom[index].src);
}
return res;
}
Object Pascal版:
function ReplaceStr(s, SourceText, DestText: String):String;
var st,res:string;
i:Integer;
begin
ReplaceStr:='';
if ((s='') or (SourceText='')) then
Exit;
st:=s;
res:='';
i:=Pos(SourceText,s);
while (i>0)do
begin
res:=res+Copy(st,1,i-1)+DestText;
Delete(st,1,(i+Length(SourceText)-1));
{if (DestText<>'') then
Insert(DestText,st,i);}
i:=Pos(SourceText,st);
end;
res:=res+st;
ReplaceStr:=res;
end;