请问,判断一个字符串是否为数字的函数是什么?

解决方案 »

  1.   

    Result := True;
    try
      StrToInt(s);
    except
      Result := False;
    end;
      

  2.   

    {判断字符是否是数字}
    function IsDigit(ch: char): boolean;
    begin
      Result := ch in ['0'..'9'];
    end;
      

  3.   

    不行呀,当字符串不是数字时,运行会出错'aa' is not a valid integer value
      

  4.   

    没有vb里的isNumber()相同功能的函数吗?
      

  5.   

    use Variants   VarIsNumeric(const V: Variant): Boolean;
      

  6.   

    有啊
    function IsNumeric(c: char): Boolean;
      

  7.   

    在一楼的语句前面加上关闭调试开关,似乎是_D,这样在运行时出错就不会报,别忘了在后面打开!
    (我在网吧,查不到,不过我记得delphi自己处理打开文件的.pas里就用过,自己看看)
      

  8.   

    Result := True;
    try
      StrToInt(s);
    except
      showmessage('只能输入数字');
    end;
      
      

  9.   

    Result := True;
    try
      StrToInt(s);
    except
      Result := False;
    end;if Result=true then ... else ...
      

  10.   

    function isfloat(txt: string):boolean;
    var  i:integer;begin
    for i:=1 to length(txt) do
       if  (txt[i] in ['0'..'9']) or (txt='.') then  Result :=true
       else Result :=false;end;
    function isint(txt: string):boolean;
    var  i:integer;begin
    for i:=1 to length(txt) do
       if  (txt[i] in ['0'..'9'])  then  Result :=true
       else Result :=false;
    end;
      

  11.   

    抓异常,没有好办法,
    对应事件:
    try
      StrToInt(s);
    except
      showmessage('请输入数值!');
    end;
      

  12.   

    for i:=1 to length(txt) do
       if  (txt[i] in ['0'..'9']) or (txt='.') then  Result :=true
       else Result :=false;
    这段代码还得考虑一个字符窜中出现两个以上的‘。’!
      

  13.   

    Indicates whether the specified variant represents a numeric value.Unit     VariantsCategoryVariant support routinesDelphi syntax:function VarIsNumeric(const V: Variant): Boolean;DescriptionVarIsNumeric returns true if the given variant's type code indicates a numeric value of some sort. This can be either a floating-point value or an ordinal value. If the variant contains any other type of value, the function result is false.
      

  14.   

    TryStrToFloat
    TryStrToCurr
    TryStrToInt
    ...
      

  15.   

    try
      StrToInt(s);
    except
      Result := False;
    end;
      

  16.   

    function IsNumber(s: string): Boolean;
    var
      err: integer;
      v: integer;
    begin
      val(s, v, err);
      Result := err > 0;
    end;
      

  17.   

    你可以逐个取去字符串中的各个字符,进行判断
    int i ;
    i :=0;
    while i <=Length(str) do 
    if   str[i] in ['0'..'9']
     then  inc(i)
     else  showmessage('不是数字 '); 
      

  18.   

    1、利用delphi 自己的异常来处理
    2、利用ascii码判断