如何判断是数字,或者是其他的字符,或者说是汉字???

解决方案 »

  1.   

    把它转换到char*,然后根据每个char 就可以判断了,48~57数字,字符,大于127的为汉字。
      

  2.   

    static int IsNum(CString str)
    {
    if(str.IsEmpty())
    return -1 ;

    int nDot = 0 ;
    //数值只能是0到9及小数点组成
    for(int i =0 ; i < str.GetLength() ; i++ )
    {
    char ch = str.GetAt(i);
    if('.' == ch )//小数点
    {
    nDot ++ ;
    continue ;
    }
    if(ch >='0' && ch <= '9')//数字
    continue ;

    return -2 ;//非法字符
    }

    if(nDot > 1)
    return -3 ;//小数点多于两个
    else if(0 == nDot)
    return 1 ;//整数
    else if(1 == nDot)
    return 0 ;//浮点数

    return -1000 ;//未知错误

    }
      

  3.   

    取出每个字符!
    IsNumber();//判断是数字
    IsCharAlpha();//判断是字符
    汉字是双字节的!
    IsDBCLeadByte();//判断字节是汉字的前一个还是后一个字节
      

  4.   

    CSting sss;
    ...
    CharNext(sss) 将获得sss的第一个字符,该字符可能是ascII或全角码字符,
    然后判断这个字符的长度,大于2就是汉字或其他ucode,若是asc码,就在判断是数字或字符
    (减去‘0’判断结果是否在0~9以内)
      

  5.   

    C 中有标准的函数,如 isnumber, isspace, isalpha etc...
      

  6.   

    CString str = "a1我3b靠c4";
    int nCharCount = 0;//字符个数
    int nChineseCount = 0;//汉字个数
    CString strNum = "";
    CString strTemp;
    for(int i = 0; i < str.GetLength(); i++)
    {
    if( (BYTE)str[i] < 0x80 ) 
    {
    nCharCount++;
    if(str[i] >= '0' && str[i] <= '9')
    {
    strTemp.Format("%c", str[i]);
    strNum += strTemp + " ";
    }
    }
    else
    {
    nCharCount++;
    nChineseCount++;
    i++;
    }
    }
    AfxMessageBox(strNum);
      

  7.   

    CString strTest = "DFGSDDF";strTest.GetLength();   //获得长度