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
    JAVA
    软件工程概论
    大道至简杂记
    InvokeRequired和Invoke
    C#代码:用事件模式实现通知
    VS 2012 C#快捷键
    error LNK2026: 模块对于 SAFESEH 映像是不安全的
    写EXCEL(csv 可以用EXECEL打开,逗号分列隔符)
    防止界面卡顿
  • 原文地址:https://www.cnblogs.com/hllak/p/4368763.html
Copyright © 2011-2022 走看看