我想取一个字符串的长度,要求一个汉字,或者一个字符,或者一个数字,或者一个字母返回的取到的长度都是1。谢谢

解决方案 »

  1.   

    http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=25399
    http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=83989
    http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=192415
      

  2.   

    int wslen(LPCTSTR s)
    {
    ASSERT(s != NULL);
    int iLen = strlen(s) + 1;
    WCHAR *ws = NULL;
    int iNeed = MultiByteToWideChar(CP_ACP, 0, s, iLen, ws, 0);
    ws = new WCHAR[iNeed + 1];
    MultiByteToWideChar(CP_ACP, 0, s, iLen, ws, iNeed);
    iLen = wcslen(ws);
    delete[]ws;
    return iLen;
    }上面的函数就可以了!
      

  3.   

    #include <mbstring.h>
    size_t _mbslen( const unsigned char *string );
      

  4.   

    lstrlen Function--------------------------------------------------------------------------------The lstrlen function returns the length in bytes (ANSI version) or WCHAR values (Unicode version) of the specified string (not including the terminating null character).