永发信息网

delphi while语句死循环

答案:2  悬赏:80  手机版
解决时间 2021-02-14 08:30
  • 提问者网友:ミ烙印ゝ
  • 2021-02-14 04:35
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
最佳答案
  • 五星知识达人网友:你哪知我潦倒为你
  • 2021-02-14 05:00
(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));
全部回答
  • 1楼网友:不想翻身的咸鱼
  • 2021-02-14 06:02
function getnum(ibeg,iend:integer):ingteger; var num:integer; begin if ibeg > iend then //ibeg iend互换 begin num:= ibeg; ibeg:= iend; iend:= num; num:= 0; end; while ibeg <= iend do begin num:=num + ibeg; ibeg:=ibeg + 1; end; result:=num; end; 你要非喜欢用if就 function getnum(ibeg,iend:integer):ingteger; var num:integer; begin while 1 = 1 do //死循环 begin num:=num + ibeg; ibeg:=ibeg + 1; if ibeg > iend then break; //符合条件打断 end; result:=num; end;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯