zoukankan      html  css  js  c++  java
  • MFC格式转换 UTF8 ANSI UNICODE

    函数拿起来就可以用

    参数说明:sChartSet : FromANSI(ANSI->UNICODE) , ToANSI (UNICODE->ANSI) , FromUTF8 (UTF8->UNICODE) , ToUTF8 (UNICODE->UTF8)

    CString CSqlConTestDlg::UnicodeCovert(CString sSourceStr , CString sCharSet)

    {

             bool bToUnicode = true;

             if(!strnicmp(sCharSet,"To",2))

             {

                       sCharSet = sCharSet.Mid(2);

                       bToUnicode = FALSE;

             }

             else if(!strnicmp(sCharSet,"From",4))

             {

                       sCharSet = sCharSet.Mid(4);

             }

             else

             {

                       return "";

             }

             UINT nCodePage = CP_ACP;

             if(stricmp(sCharSet,"ANSI") == 0 || stricmp(sCharSet,"ACP") == 0)

                       nCodePage = CP_ACP; //ANSI translation

             else if(stricmp(sCharSet,"UTF8") == 0)

                       nCodePage = CP_UTF8; //UTF8 translation

             else

                       return "";

             CString sCovert;

             if(bToUnicode) //->Unicode

             {

                       DWORD nWideBuf = MultiByteToWideChar(nCodePage , 0 , (LPCTSTR)sSourceStr , sSourceStr.GetLength(),NULL,0); //探测转成Unicode的长度

                       sCovert.GetBufferSetLength(nWideBuf*2);

                       MultiByteToWideChar(nCodePage,0,(LPCTSTR)sSourceStr,sSourceStr.GetLength(),(LPWSTR)LPCTSTR(sCovert),nWideBuf);

             }

             else //Unicode - >

             {

                       DWORD nWideCount = (sSourceStr.GetLength() + 1) * 2;

                       if(nWideCount == 0)

                                sCovert.Empty();

                       else

                       {

                                int nMultilen = WideCharToMultiByte(nCodePage, 0 , (LPWSTR)LPCTSTR(sSourceStr),nWideCount,sCovert.GetBufferSetLength(nWideCount),0);

                                sCovert.GetBufferSetLength(nMultilen);

                       }

             }

             return sCovert;

    }

  • 相关阅读:
    查看mysql日志
    Redis配置和常用命令
    任务
    如何让maven 将工程依赖的jar 复制到WEB-INF/lib 目录下
    Tomcat8安装, 安全配置与性能优化(转)
    Web.xml详解(转)
    php精度比较函数bccomp
    php找到字符数组里最左匹配长度的字符(最长公共前缀匹配算法)
    PHP实现curl post和get
    Jquery 跨Dom窗口操作
  • 原文地址:https://www.cnblogs.com/zzhua/p/5808532.html
Copyright © 2011-2022 走看看