vc 判断一个字符串是否位数字,且判断此数字的范围

来源:岁月联盟 编辑:exp 时间:2012-11-19

//返回1正确,返回0不是

以为是判断端口的,数字范围设在了1-65535

一下是函数代码:

[cpp]
//返回1正确,返回0错误 
int isRight(CString str) 
{   www.2cto.com
    BOOL bIsDigit = TRUE; 
    int nCount = str.GetLength(); // 获得字符个数 
    for ( int i = 0; i < nCount; i ++ ) 
    { 
        if ( 0 == isdigit( str.GetAt(i) ) ) // 不是数字就置标志位 
        { 
            return 0; 
        } 
    } 
    int temp = atoi(str); 
    if (temp>0 && temp < 65536) 
    { 
        return 1; 
    } 
    return 0;