• 多字节


    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];  
    

    }

  • 相关阅读:
    算法解读:基本的算法
    算法解读:数据结构
    算法解读:s变量和数组
    软件测试之构建测试---BVT
    什么是算法?——算法轻松入门
    大道至简——软件工程实践者的思想读书笔记四
    软件测试之安装测试
    大道至简——软件工程实践者的思想读书笔记三
    软件测试人员成长必备知识篇
    大道至简——软件工程实践者的思想读书笔记二
  • 原文地址:https://www.cnblogs.com/hllak/p/4368763.html
Copyright © 2020-2023  润新知