delphi while语句死循环

来源:百度知道 编辑:UC知道 时间:2024/06/16 11:42:09
function GetBody3(const x , y,z: string): string; //在x中查找y开头,z结尾的
var
ipos1: integer;
ipos2: integer;
str:string;
begin
while((Pos(y, x)>0)and (Pos(z, x)>0)) do
begin
iPos1 := Pos(y, x);
iPos2 := Pos(z, x);
str:=Copy(z, iPos1, ipos2-ipos1);
result:= StringReplace(z, str, '', [rfReplaceAll]);
end;
end;

但是x是const

(1)如果只想查一次就在 result:= StringReplace(z, str, '', [rfReplaceAll]);后面加 break;

(2)查多条就在result:= StringReplace(z, str, '', [rfReplaceAll]); 后面加:x := copy(x, 1, iPos1-1) + copy(x, ipos2 + length(z), length(x));