zoukankan      html  css  js  c++  java
  • Delphi 判断一个字符串是否为数字

    //函 数 名: IsDigit
    //返 回 值: boolean
    //日       期:2011-03-01
    //参       数: String
    //功       能: 判断一个字符串是否为数字
    //作       者:liubin
    //***************************************************************************

    function IsDigit(S:String):Boolean; //变量S为要判断的字符串,返回true则正确
    var
    i,j:integer;

    begin
        Result:=True;
        j :=0 ;
        for i :=1 to length(s) do
        begin
           if not (s[i] in ['0'..'9','.'])then   //判断字符串每个字符即s[i],是否为"0"到'9"数字及".'
             Result:=False;
           if s[i]='.' Then //统计字符串中"."的个数
             j:=j+1;
        end;

        if j > 1 then   //字符串中"."的个数大于1
           Result:=False;

        if (s[1]='.') or (s[length(s)]='.') then //字符串中"."的在最前面和最后面
           Result:=False;
        //增加, 字符串中"."的位置之前有两个"0"判断
        s:=copy(s,1, pos('.', S)-1); //取字符串中"."的位置之前字符
        j:=0;
        for i:=1 to length(s) do
        begin
           if s[i]='0' then
              j:=j+1;
        end;

        if j > 1 then    //字符串中"."的位置之前有两个"0"
           Result:=False;
    end;

  • 相关阅读:
    mongodb安装
    node版本的管理 n
    npm 命令
    nodejs,npm安装(ubuntu14.04下)
    yeoman,grunt,bower安装(ubuntu14.04)
    什么是堆和栈,它们在哪儿?
    malloc函数详解 (与new对比)
    单链表的C++实现(采用模板类)
    短信验证码
    webapi
  • 原文地址:https://www.cnblogs.com/jijm123/p/8290542.html
Copyright © 2011-2022 走看看