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

    }

  • 相关阅读:
    python线程、线程池
    day10 知识点
    socketserver 进阶之I/O多路复用
    socketserver
    socket
    设计模式
    剑指offer:整数中1出现的次数
    剑指offer:二叉搜索树与双向链表
    剑指offer:扑克牌顺子
    剑指offer:孩子们的游戏(圆圈中最后剩下的数)
  • 原文地址:https://www.cnblogs.com/hllak/p/4368763.html
Copyright © 2011-2022 走看看