zoukankan      html  css  js  c++  java
  • Unicode/not set/multibyte/部分常用函数

    字符编码

          两种字符类型 char  / wchar_t

          TCHAR是一个宏

                                       多字节编码时:替换为char

                                       Unicode编码时:替换为wchar_t

    l      不能使用strcpy这样的ANSI C字符串函数处理wchar_t字符串,须使用wcs前缀的函数。

    l      为了使编译器识别Unicode字符串,在字符串前面加L前缀。

    wchar_t *szTest = L”This is a Unicode string”;

    l      使用TCHAR: 不应该使用ANSIstrxxxUnicodewcsxxx 须使用Tchar.h中定义的_tcsxxx,并用_TEXT代替L

    l       

    函数

    *     _tcslwr 将字符串转化成小写字母(VS2005+WinCE6.3

    *     lstrcpy 复制(VS2005+WinCE6.3

    Cstring TCHAR

    TCHAR之间的复制

    lstrcpy(TCHAR  , TCHAR);

    lstrcpy(TCHAR  , CString);

          CString str= _T("VS");

           printf("str.getlength()=%d/n",str.GetLength()); //Unicode3个字符  //not set 4个字节。//mult 4//not set ==mult??

           int a;

           a=wcslen(str);

           printf("a=%d/n",a);//3

           a=_tcslen(str);

           printf("a=%d/n",a);//3

     

           TCHAR tstr[10];

           a=wcslen(tstr);printf("a=%d/n",a);//1  

           lstrcpy(tstr,str);

           a=wcslen(tstr);printf("a=%d/n",a);//3

     

    、、、、、、、、、、、、、、、、、、、、、、、、、、、、、winbase.h

    #define lstrcpyW wcscpy

    #ifdef UNICODE

    #define lstrcpy lstrcpyW

    #else

    #define lstrcpy lstrcpyA

    #endif

    、、、、、、、、、、、、、、、、、、、、、、、、、、、tchar.h

    #define _tcscpy         wcscpy

     

     

    *     wsprintf 复制(VS2005+WinCE6.3

    TCHAR *CurrentPath;

    TCHAR CurrentFullPath[MAX_PATH];

    wsprintf(CurrentFullPath,TEXT("%ls//*.*"),CurrentPath);

     

    winbase.h中:

    #ifdef UNICODE

    #define wsprintf wsprintfW

    #else

    #define wsprintf wsprintfA

    #endif

     

    *     wcslen 获取字符串长度(环境VS2005

    if(0==wcslen(CurrentPath)){};

    wcslen(CString)multi-byte/not set字符集编译错误

    cannot convert parameter 1 from 'CString' to 'const wchar_t *'

    Unicode字符集正确,返回字符数。同Cstring.GetLength();

    #define _tcslen         wcslen //tchar.h

    _tcslen  multi-byte/not set/Unicode均可以用,在Unicode下返回字符数,在multi-byte/not set下返回字节数。

    以上结果在PC上得出,

    wince6.3版本在multi-byte/not set 情况下报错,只能用Unicode,应该与所有SDK有关。

    WinCE6.3 +Unicode:

    Cstring str=_T(VS);

    wcslen(str)==_tcslen(str)==str.GetLength()==3

    strlen(str):报错,

    cannot convert parameter 1 from 'CString' to 'const char *'

     

    *     wmemcmp比较字符串 VS2005+WinCE6.3

    if(wmemcmp(FolderName,_T("//网络"),wcslen(FolderName))==0){// 等于零代表想同}

    *     _wcsuper 字符串小写换为大写(VS2005+WinCE6.3

    TCHAR *FileName;

    //赋值

    TCHAR *UpperFileName =_wcsupr(FileName);

    *      

    *      字符集转化函数

    MultiByteToWideChar

            WideCharToMultiByte

            LCMapString (简体与繁体转化)

     

     

     

    悲催的,脑袋僵的很,明明知道Unicode一个字符两个字节,还一直想怎么获取一个CString 的字节数!    字符数*2!!!!弱弱弱

  • 相关阅读:
    ASP.NET2.0中用Gridview控件操作数据
    有关petShop的几篇文章
    用多活动结果集优化ADO.NET2.0数据连接
    设计数据层组件并在层间传递数据
    google的语法?
    PHP导出Excel方法
    header ContentType类型
    40条优化php代码的小实例
    strstr 不错的技巧
    PHP 截取字符串专题
  • 原文地址:https://www.cnblogs.com/ezhong/p/2171477.html
Copyright © 2011-2022 走看看