1、Unicode转UTF-8

 void CodeCovertTool::UNICODE_to_UTF8(const CString& unicodeString, std::string& str)
{//Unicode转UTF8
int stringLength = ::WideCharToMultiByte(CP_UTF8, NULL, unicodeString, wcslen(unicodeString), NULL, , NULL, NULL); char* buffer = new char[stringLength + ];
::WideCharToMultiByte(CP_UTF8, NULL, unicodeString, wcslen(unicodeString), buffer, stringLength, NULL, NULL);
buffer[stringLength] = '\0'; str = buffer; delete[] buffer;
}
 std::string CodeCovertTool::UnicodeToUtf8(const wchar_t* buf)
{//Unicode转UTF8
int len = ::WideCharToMultiByte(CP_UTF8, , buf, -, NULL, , NULL, NULL);
if (len == ) return ""; std::vector<char> utf8(len);
::WideCharToMultiByte(CP_UTF8, , buf, -, &utf8[], len, NULL, NULL); return &utf8[];
}

2、UTF-8转Unicode

 std::wstring CodeCovertTool::Utf8ToUnicode(const char* buf)
{//UTF8转Unicode
int len = ::MultiByteToWideChar(CP_UTF8, , buf, -, NULL, );
if (len == ) return _T(""); std::vector<wchar_t> unicode(len);
::MultiByteToWideChar(CP_UTF8, , buf, -, &unicode[], len); return &unicode[];
}
 CString CodeCovertTool::Utf8ToUnicode(const std::string &utf8_str)
{//UTF8转Unicode
int len;
len = MultiByteToWideChar(CP_UTF8, , (LPCSTR)utf8_str.c_str(), -, NULL,);
WCHAR * wszUnicode = new WCHAR[len+];
memset(wszUnicode, , len * + );
MultiByteToWideChar(CP_UTF8, , (LPCSTR)utf8_str.c_str(), -, wszUnicode, len);
CString ss=wszUnicode;
delete wszUnicode;
return ss;
}

3、Ansi转Unicode

 std::wstring CodeCovertTool::AnsiToUnicode(const char* buf)
{//Ansi转Unicode
int len = ::MultiByteToWideChar(CP_ACP, , buf, -, NULL, );
if (len == ) return L""; std::vector<wchar_t> unicode(len);
::MultiByteToWideChar(CP_ACP, , buf, -, &unicode[], len); return &unicode[];
}

4、Unicode转Ansi

 std::string CodeCovertTool::UnicodeToAnsi(const wchar_t* buf)
{//Unicode转Ansi
int len = ::WideCharToMultiByte(CP_ACP, , buf, -, NULL, , NULL, NULL);
if (len == ) return ""; std::vector<char> utf8(len);
::WideCharToMultiByte(CP_ACP, , buf, -, &utf8[], len, NULL, NULL); return &utf8[];
}

UTF-8和Unicode互转的更多相关文章

  1. php 中文unicode 互转

    /** * $str 原始中文字符串 * $encoding 原始字符串的编码,默认GBK * $prefix 编码后的前缀,默认"&#" * $postfix 编码后的后 ...

  2. Unicode 互转

    // 转为unicode 编码 function encodeUnicode(str) { var res = []; ; i<str.length; i++ ) { res[i] = ( ) ...

  3. 中文和unicode互转

    public class Test { public static void main(String[] args) { String uname="欧阳红"; for (int ...

  4. Java 16进制、unicode互转

    package service; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CodeCh ...

  5. Java - 字符串和Unicode互转 - 解析小米pm.min.js

    小米JS地址: http://p.www.xiaomi.com/zt/20130313/huodong/pm.min.js 上面这个JS是小米抢手机页面的代码.和抢手机有直接关联.. 虽然我3次都没抢 ...

  6. java 中文与unicode互转

    public class FontUtil { public static void main(String[] args) { System.out.println(chinaToUnicode(& ...

  7. java字符串和unicode互转

    直接上代码 private static String decodeUnicode(String input) { if (null == input) return input; int len = ...

  8. Unicode、UTF-8 和 ISO8859-1到底有什么区别

    说明:本文转载于新浪博客,旨在方便知识总结.原文地址:http://blog.sina.com.cn/s/blog_673c81990100t1lc.html 本文主要包括以下几个方面:编码基本知识, ...

  9. 使用 WideCharToMultiByte Unicode 与 UTF-8互转

    1.简述 最近在发送网络请求时遇到了中文字符乱码的问题,在代码中调试字符正常,用抓包工具抓的包中文字符显示正常,就是发送到服务器就显示乱码了,那就要将客户端和服务器设置统一的编码(UTF-8),而我们 ...

随机推荐

  1. node开发后将本地mysql数据导入到服务器mysql

    近期写的一个钉钉企业微应用用到了mysql数据库(用koa写的后台,并用mysql库来连接),现在需要把本地数据库的数据导入到服务器的数据库中. 服务器安装mysql 可以google篇centos的 ...

  2. windows常用命令(转载)

    1.最基本,最常用的,测试物理网络的  ping 192.168.0.8 -t ,参数-t是等待用户去中断测试 2.查看DNS.IP.Mac等  A.Win98:winipcfg  B.Win2000 ...

  3. javascript和c#的深度拷贝的一种通用方法

    很简单,序列化后反序列化...

  4. uGUI动态加载控件位置错误(转自:https://www.cnblogs.com/mezero/p/4542939.html)

    最近在使用uGUI时遇到了一个问题,在此记录一下.在Canvas的Render Mode设置为Screen Space-Overlay模式时,动态加载控件是不会发生问题的.但是在Screen Spac ...

  5. EasyRTMP手机直播推送rtmp流flash无法正常播放问题

    本文转自EasyDarwin团队Kim的博客:http://blog.csdn.net/jinlong0603/article/details/52960750 问题简介 EasyRTMP是EasyD ...

  6. Embed image in a <button> element 微信小程序 客服按钮

    html - Embed image in a <button> element - Stack Overflow https://stackoverflow.com/questions/ ...

  7. lazy evaluation and deferring a computation await promise async

    Promise - JavaScript | MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_ ...

  8. mybatis入门(十)

    mybatis和hibernate本质区别和应用场景 hibernate:是一个标准ORM框架(对象关系映射).入门门槛较高的,不需要程序写sql,sql语句自动生成了. 对sql语句进行优化.修改比 ...

  9. 用css3技术给网站加分

    自己写了几个小DEMO,请打开http://codepen.io/shenggen/

  10. [自动化平台系列] - 初次使用 Macaca-前端自动化测试(3)

    1. 如果是一个列表页面,当要触发编辑页面是如何做的呢?其实我测试只要点击第一条数据去编辑就好啦!如果页面结构如下 <li class="myatc-li"> < ...