zoukankan      html  css  js  c++  java
  • How to deal with the messy code when using MariaDB for Chinese

    For compatibility, using the code of UTF-8.

    Due to the code of VS using GBK2312, so must transfer the UTF-8 to mysql_query.

    I use the code of this:

     1 CStringW trans2CW(const char * wch, int type = CP_ACP) {  
     2     int len1 = MultiByteToWideChar(CP_ACP, 0, wch, -1, NULL, 0);   
     3 
     4     //exchanged
     5     wchar_t * pwtr = new wchar_t[len1+1];  
     6     int len2 = MultiByteToWideChar(CP_ACP, 0, wch, -1, pwtr, len1);  
     7     CStringW str(pwtr);
     8     delete[] pwtr;
     9     return str;  
    10 } 
    11 
    12 CString WCS2UTF8(const wchar_t* szU8)
    13 {
    14     //get the length of space
    15     int len;
    16     len = WideCharToMultiByte(CP_UTF8, 0, szU8, -1, NULL, 0, NULL, NULL);
    17     char *szUtf8 = new char[len + 1];
    18     memset(szUtf8, 0, len + 1);
    19     WideCharToMultiByte(CP_UTF8, 0, szU8, -1, szUtf8, len, NULL, NULL);
    20     return szUtf8;
    21 
    22     CString unicodeString(szUtf8);
    23 
    24     delete[] szUtf8;
    25     szUtf8 = NULL;
    26     return unicodeString;
    27 }

    The demo will be like:

  • 相关阅读:
    日志/异常处理(nnlog+traceback)
    Excel操作
    商品管理系统
    大乐透作业
    随机生成密码作业
    时间相关的模块
    os模块
    sys模块
    Pytho中dict(或对象)与json之间的互相转化
    Python三元表达式和列表生成式
  • 原文地址:https://www.cnblogs.com/WaterGood/p/12270916.html
Copyright © 2011-2022 走看看