什么编码?一般而言,只能判断他是否为ASCII (byteVal>128?true:false)

解决方案 »

  1.   

    首先你要把字符串换成UNICODE
    使用MultiByteToWideChar可以做到分别判断首字节与尾字节
    如下
    CHAR *szBuf = "asdfasdf在小"
    WCHAR wcBuf[1024];
    memset(wcBuf, 0, sizeof(WCHAR)*1024);
    int l = MultiByteToWideChar(CP_ACP, 0, szBuf, strlen(szBuf), wcBuf, 1024);
    for(int i = 0;i<l;i++)
    {
    char firstchar =(char)( wcBuf[i]&0x00ff );
    char lastchar =(char) (wcBuf[i]>>8);
        if(   (  (firstchar>=0xa1) && (firstchar<=f7) )
              (  (lastchar>=0xa1) &&(lastchar<=fe) ) )
        {
           //此字符是汉字
        }
        else
        {
           //此字符不是汉字
        }
    }提示:gb码的编码范围是首字节a1-f7,尾字节a1-fe,
    祝你好运!!!