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;

    }

  • 相关阅读:
    随机生成字符串,可用来当id
    自己总结的关于uniapp项目用androidstuido打包成apk
    css3 滑动效果 门
    在数组里面随机获取随机的几个内容
    把一个数组分割成两个(不管奇数还是偶数)
    Mysql常用命令
    怎样才能彻底地删除多余输入法软件
    启动MySQL服务
    linux监控命令全覆盖
    浅谈MVC模式与SSH框架
  • 原文地址:https://www.cnblogs.com/zzhua/p/5808532.html
Copyright © 2011-2022 走看看