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;

    }

  • 相关阅读:
    改变UINavigationBar颜色需要注意的地方
    更改ios状态栏颜色
    多线程简单介绍
    GCD多线程的实现方法
    NSUserDefaults的简单介绍
    NSFileManager的简单介绍,在沙盒目录下对文件进行增删改查
    在plist文件中增删改查
    frame bound center等之间的关系
    《汇编语言》——王爽 第五章 [BX]和loop指令
    《汇编语言》——王爽 第四章 第一个程序
  • 原文地址:https://www.cnblogs.com/zzhua/p/5808532.html
Copyright © 2011-2022 走看看