procedure TMainForm.Button2Click(Sender: TObject);
var
i,c,v,Sum: Integer;
s: string;
begin
Sum := 0;
s := '1-22-42+464';
while s <> '' do
begin
c := Pos('+',s);
v := Pos('-',s);
if (c < v) and (c <> 0) then
begin
Sum := Sum + StrToInt(Copy(s,1,c));
Delete(s,1,c);
end;
if (v < c) and (v <> 0) then
begin
Sum := Sum + StrToInt(Copy(s,1,v));
Delete(s,1,v);
end;
end;
Business.Forms.jsDialogs.ShowMsg(IntToStr(Sum),'');
end;
上面的思路无论怎么调整总是有BUG,您看看这方法是否行的同 |