如何判断一字符串是否为数字串?
如: '123.456000' 为数字,但'+123Edfd我12'为非字符串.
而'+123E-7',为数字串.
Delphi7帮助中:
对function StrToFloat(const S: string): Extended; overload;
中S的定义
S must consist of an optional sign (+ or -), a string of digits with an optional decimal point, and an optional mantissa. The mantissa consists of 'E' or 'e' followed by an optional sign (+ or -) and a whole number. Leading and trailing blanks are ignored.若S为'+123Edfd我12',通过StrToFloat转换不成功,会引发EConvertError
异常.
能否通过这一点来判断S是否为数字串?(最好能简化为用if 判断)
本人一直以来对异常(C++,Delphi)都不明白,Delphi也刚学不久,望哪位大侠赐教!

解决方案 »

  1.   

    var Str: String;
        NumReal: Real;Try
       NumReal := StrToFloat(Str);
    Except
       ShowMessage(Str+' 不是一個有效的數值 ');
       //Abort;
       .....
    End;
       
      

  2.   

    function IsNumString(s: String): Boolean;
    begin
      Result := True;
      try
        n := StrToInt('你的字符串');
        //类似的,其他类型数字用相应的函数
      except
        //如果不是数字字符串会出错,执行这里的代码
        Result := False;
      end;
    end;
      

  3.   

    同意Bes96261(秋水孤鶩) 的,Taken(铁拳) 你的函数中 n := StrToInt('你的字符串')只可以判断整形的数据!楼主是要浮点数类型的