请问有没有函数判断一个字符串是否是数字
如输入“123”则返回是
  输入“123abc”则返回不是

解决方案 »

  1.   

    var number: Integer;
    begin
      try
        number := StrToInt(str);
        result := true;
      except
        result := false;
      end;
    end;
      

  2.   

    ifkey not in [0..9] then
      false
    else
      true;
      

  3.   

    try
        StrToInt('123');
        result := true;
      except
        on E:EConvertError do
          result := false;
      end;
      

  4.   

    var
       str1: string;
       i: integer;
    begin
       str1 := Edit1.Text;
       for i:=1 to length(str1) do
       begin
          if str[i] in ['0'..'9'] then
             Flag := True;
          else
          begin
             ShowMessage('不是数字');
             Flag := False;
             Break;
          end;
    ...
    end;
      

  5.   

    StrToInt()只是对整型值有效,如果是浮点数就没用啦,遍历字符串,首先分析小数点的个数是否大于1,大于1,当然就不是数,反之就逐个分析字符串中每一个字符的ASII码是不是在0和9之间,或是小数点。
      

  6.   

    StrToInt()只是对整型值有效,如果是浮点数就没用啦,我想应该这样做:
        首先分析小数点的个数是否大于1,大于1,当然就不是数,反之就遍历字符串,逐个分析字符串中每一个字符的ASII码是不是在0和9之间,或是小数点。
      

  7.   

    kyo1979 (绝望的生鱼片),怎么不给我分呢?