如何判断一个字符串代表一个数字如:'12345'?

解决方案 »

  1.   

    try
      StrToInt('123456');
      ShowMessage('是數字');
    except
      ShowMessage('不是數字');
    end;
      

  2.   

    if IsNumeric('1234') then
       是数字
    else
       不是数字
      

  3.   

    try
      StrToInt('123456');
      ShowMessage('是數字');
    except
      ShowMessage('不是數字');
    end;strtoint的异常好像try..except捕捉不到。
      

  4.   

    if IntToStrDef('12345',-1)<>-1 then
    // true
      

  5.   

    function compare_val(s: string): Boolean;
    var
      i:integer;
    begin
    Result:=True;
    for i := 1 to length(s) do  begin
     if ( (Ord(s[i])<48) or( Ord(s[i])> 57))   then
        Result:=False;
     end;
    end;
      

  6.   

    var int_R:integer;
    begin
       int_R:=StrToIntDef('Hello World',0);
       ShowMessage('Hello World To int is '+intToStr(int_R));
    end;