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. Zabbix 3.0安装

    Server 1. rpm安装zabbix 3.0最新的epel源 rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-re ...

  2. [网页游戏开发]Morn简介及使用教程

    网页游戏开发利器,morn系列教程之Morn简介及使用教程 网页游戏开发的一大部分工作是在和UI制作上,一个好的工具及框架能使开发事半功倍,Adobe自带flash IDE和Flex各有不足. Mor ...

  3. linux shell 的前世今生和流行BASH SHELL的特点

    前言 shell作为用户和操作系统内核交互的接口,也不断的在发展迭代.shell的发展也离不开unix/linux 系统的发展.并且在开源社区对shell的发展也起到了推动作用. 内容思维导图简介 发 ...

  4. SQL还原数据库后,数据库显示受限制用户解决方法

    数据库->属性->选项

  5. IOS之禁用UIWebView的默认交互行为

    本文转载至 http://my.oschina.net/hmj/blog/111344       UIKit提供UIWebView组件,允许开发者在App中嵌入Web页面.通过UIWebView组件 ...

  6. 基于EasyIPCamera实现的RTSP跨平台拉模式转发流媒体服务器

    本文转自博客:http://blog.csdn.net/xinlanbobo/article/details/53224445 上一篇博客<EasyIPCamera通过RTSP协议接入海康.大华 ...

  7. Darwin Streaming Server性能测试报告

    为了验证Darwin Streaming Server在流媒体点播上的性能,EasyDarwin开源项目官方特地与国内某大型视频网站进行了一次性能测试(千兆网络环境下),针对本次RTSP直播流媒体测试 ...

  8. Two-Factor Authentication 2FA

    About two-factor authentication - User Documentation https://help.github.com/articles/about-two-fact ...

  9. git基本操作---持续更新(2017-08-11)

    git 强制push $ git push -u origin master -f 查看本地标签 $ git tag 打标签并添加备注 $ git tag 20170811 -m"图片保存多 ...

  10. 剑指Offer:重建二叉树【7】

    剑指Offer:重建二叉树[7] 题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5 ...