zoukankan      html  css  js  c++  java
  • 多字节

    void ConvertGBKToUtf8(CString& strGBK)
    {
    int len=MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, NULL,0);
    unsigned short * wszUtf8 = new unsigned short[len+1];
    memset(wszUtf8, 0, len * 2 + 2);
    MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, wszUtf8, len);

         len = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, NULL);
         char *szUtf8=new char[len + 1];
         memset(szUtf8, 0, len + 1);        
         WideCharToMultiByte (CP_UTF8, 0, wszUtf8, -1, szUtf8, len, NULL,NULL);
    
         strGBK = szUtf8;
         delete[] szUtf8;                
         delete[] wszUtf8;                
    

    }

    void ConvertUtf8ToGBK(CString& strUtf8)
    {
    int len=MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, NULL,0);
    unsigned short * wszGBK = new unsigned short[len+1];
    memset(wszGBK, 0, len * 2 + 2);
    MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, wszGBK, len);

         len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
         char *szGBK=new char[len + 1];
         memset(szGBK, 0, len + 1);
         WideCharToMultiByte (CP_ACP, 0, wszGBK, -1, szGBK, len, NULL,NULL);
    
         strUtf8 = szGBK;
         delete[] szGBK;
         delete[] wszGBK;
    

    }

    qp::StringW Global::AnsiToUnicode(const char* buf)
    {
    int len = ::MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
    if (len == 0) return L"";

    std::vector<wchar_t> unicode(len);  
    ::MultiByteToWideChar(CP_ACP, 0, buf, -1, &unicode[0], len);  
    
    return &unicode[0];  
    

    }

    qp::StringA Global::UnicodeToAnsi(const wchar_t* buf)
    {
    int len = ::WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL);
    if (len == 0) return "";

    std::vector<char> utf8(len);  
    ::WideCharToMultiByte(CP_ACP, 0, buf, -1, &utf8[0], len, NULL, NULL);  
    
    return &utf8[0];  
    

    }

    qp::StringW Global::Utf8ToUnicode(const char* buf)
    {
    int len = ::MultiByteToWideChar(CP_UTF8, 0, buf, -1, NULL, 0);
    if (len == 0) return L"";

    std::vector<wchar_t> unicode(len);  
    ::MultiByteToWideChar(CP_UTF8, 0, buf, -1, &unicode[0], len);  
    
    return &unicode[0];  
    

    }

    qp::StringA Global::UnicodeToUtf8(const wchar_t* buf)
    {
    int len = ::WideCharToMultiByte(CP_UTF8, 0, buf, -1, NULL, 0, NULL, NULL);
    if (len == 0) return "";

    std::vector<char> utf8(len);  
    ::WideCharToMultiByte(CP_UTF8, 0, buf, -1, &utf8[0], len, NULL, NULL);  
    
    return &utf8[0];  
    

    }

  • 相关阅读:
    java框架---->mybatis的使用(一)
    java基础---->数组的基础使用(二)
    python爬虫---->github上python的项目
    java基础---->git的使用(一)
    spring基础---->请求与响应的参数(一)
    织梦DEDECMS网站后台安全检测提示 加一个开关
    MySql的join(连接)查询 (三表 left join 写法)
    html只允许输入的数据校验,只允许输入字母汉字数字等
    js控制只允许输入数字
    DEDECMS里面DEDE函数解析
  • 原文地址:https://www.cnblogs.com/hllak/p/4368763.html
Copyright © 2011-2022 走看看