DELPHI把一个字符串中的某个子串,用另一个子串去替换

2018-11-24

function StrReplace(s,oldstr,newstr:string):string; //字符串替换

var

SelPos,SelLen: Integer;

begin

SelPos := Pos(oldstr, s);

while SelPos > 0 do

begin

SelLen := Length(oldstr);

delete(s,SelPos,SelLen);

insert(newstr,s,SelPos);

SelPos := Pos(oldstr, s);

end;

Result:=s;

end;


阅读25