Delphi测试题——将字符串"10ad200d3" 中的数字合计

var
i: Integer;
t1: string;
t2: Integer;
n1: Integer;
s: string;
begin
s := Edit1.Text;
if s = ‘’ then
exit
else
begin

t1 := '';
t2 := 0;
n1 := 1;
for I := 1 to Length(Edit1.Text) do
begin
  if not (s[i] in ['0'..'9', 'a'..'z', 'A'..'Z']) then
  begin
    showmessage('只允许输入数字和字母,请重输!!!');
    Edit1.Text := '';
    Edit1.SetFocus;
    Exit
  end
  else
  begin
    if s[i] in ['0'..'9'] then
    begin
      t1 := t1 + copy(s, n1, 1);
    end
    else
    begin
      if t1 <> '' then
      begin
        t2 := t2 + strtoint(t1);
        t1 := '';
      end;
    end;

    n1 := i + 1;
  end;
end;

if t1 <> '' then
  t2 := t2 + strtoint(t1);

Edit2.Text := IntToStr(t2);

end;
end;

最后得到的结果是213

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页