我在一个字符串中提取出了一部分,然后对其进行判断,判断它是不是数字?同vb的Isnumeric函数!

解决方案 »

  1.   

    function StrToInt(const S: string): Integer;StrToInt converts the string S, which represents an integer-type number in either decimal or hexadecimal notation, into a number. If S does not represent a valid number, StrToInt raises an EConvertError exception.不是数字则会产生异常,自己处理下异常先!
      

  2.   

    1.  StrToIntDef 函数可以将数据强制性转换成数字,而且不会出现出错提示。2.
    var
      I : Integer;
      S : string
    begin
      S := 'A123';
      for I:=1 to Length(S) do
        if S[I] in ['0'..'9'] then showmessage('is Number')
    end
      

  3.   

    str:='asdg56fd';for i:=0 to length(str) do
    begin
      if (byte(str[i])<97) and (byte(str[i]<125)) then
          showmessage('该字符是一个数字')
      else
        showmessage('该字符是一个字符')
          
    end;
      

  4.   

    请参考Val过程,Delhi6中,没有写在帮助中但是SysUtils单元中放出了这个函数.
    具体参见StrToInt的源代码
    uses Dialogs;
    var   I, Code: Integer;
    begin
      { Get text from TEdit control }
      Val(Edit1.Text, I, Code);
      { Error during conversion to integer? }
      if Code <> 0 then
        MessageDlg('Error at position: ' + IntToStr(Code), mtWarning, [mbOk], 0, mbOk);
      else
        Canvas.TextOut(10, 10, 'Value = ' + IntToStr(I));end;
      

  5.   

    function Isnumeric(str: string): Boolean;
    begin
      Result := Ture;
      try
        StrToFloat(str);
      except
        Result := False;
      end;
    end;
      

  6.   

    var i:integer;
    begin
      if tryStrToInt('1',i) then showmessage('正确')
      else
       showmessage('错误')
    end;
      

  7.   

    jinjazz(近身剪(N-P攻略)) 崇拜
      

  8.   

    if strtoint(i) then
       数字
    else
       字符
      

  9.   

    function IsNUM(str: string): Boolean;
    begin
      Result := Ture;
      try
        StrToFloat(str);
      except
        Result := False;
      end;
    end;
      

  10.   

    用Val函数就可以,去看帮助有例子,或按大猛料得写法:
    function IsNumber(mStr: string): Boolean; { 返回字符串是否是正确的数字表达 }
    var
      I: Real;
      E: Integer;
    begin  Val(mStr, I, E);  Result := E = 0;
    end;
      

  11.   

    楼上的,那要是还有小数的呢,不就出错了。
    我觉得  anbangs(菜鸟邦) 的可以考虑。
      

  12.   

    也简单啊..
    var
      I : Integer;
      S : string
    begin
      S := 'A123';
      for I:=1 to Length(S) do
        if S[I] in ['0'..'9','.'] then showmessage('is Number')
    end
    多个'.'就行了..
      

  13.   

    同意 fansaien(学习中) ( ) 信誉            用val最快了,最简单了