检测是否是全数字

来源:互联网 发布:js只能输入数字小数点 编辑:程序博客网 时间:2024/06/09 23:51
bool isDigitStr(const char* cstr){    if (NULL == cstr || cstr[0] == 0)    {        return false;    }    int len = strlen(cstr);    int pos = 0;    if (cstr[0] == '-' || cstr[0] == '+')    {        if (len <= 1)        {            return false;        }        pos++;    }    while (pos < len)    {        if (cstr[pos] < '0' || cstr[pos] > '9')        {            return false;        }        pos++;    }    return true;} 

0 0
原创粉丝点击