GBK转utf-8,宽字符转窄字符
//GBK转UTF8
string CAppString::GBKToUTF8(const string & strGBK)
{
string strOutUTF8 = "";
WCHAR * str1;
int n = MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, NULL, 0);
str1 = new WCHAR[n];
MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, str1, n);
n = WideCharToMultiByte(CP_UTF8, 0, str1, -1, NULL, 0, NULL, NULL);
char * str2 = new char[n];
WideCharToMultiByte(CP_UTF8, 0, str1, -1, str2, n, NULL, NULL);
strOutUTF8 = str2;
delete []str1;
str1 = NULL;
delete []str2;
str2 = NULL;
return strOutUTF8;
} //UTF8转GBK
string CAppString::UTF8ToGBK(const std::string & strUTF8)
{
int len = MultiByteToWideChar(CP_UTF8, 0, strUTF8.c_str(), -1, NULL, 0);
unsigned short * wszGBK = new unsigned short[len + 1];
memset(wszGBK, 0, len * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)strUTF8.c_str(), -1, (LPWSTR)wszGBK, len); len = WideCharToMultiByte(CP_ACP, 0, (LPWSTR)wszGBK, -1, NULL, 0, NULL, NULL);
char *szGBK = new char[len + 1];
memset(szGBK, 0, len + 1);
WideCharToMultiByte(CP_ACP,0, (LPWSTR)wszGBK, -1, szGBK, len, NULL, NULL);
//strUTF8 = szGBK;
std::string strTemp(szGBK);
delete[]szGBK;
delete[]wszGBK;
return strTemp;
} //宽字符转窄
string CAppString::Unicode2ACSII(const wstring & strSource)
{
string strDest("");
if (strSource.empty())
{
return strDest;
} int nlen = ::WideCharToMultiByte(CP_ACP, 0, strSource.c_str(), -1, NULL, 0, NULL, NULL);
char * szDest = new char[nlen + 1];
::WideCharToMultiByte(CP_ACP, 0, strSource.c_str(), -1, szDest, nlen, NULL, NULL);
strDest = szDest;
delete szDest;
szDest = NULL; return strDest;
} //窄字符转宽字符
wstring CAppString::ASCII2Unicode(const char* strSrc)
{
wchar_t* pElementText = NULL;
int nTextLen = 0;
// multi char to wide char
nTextLen = MultiByteToWideChar( CP_ACP, 0, strSrc, -1, NULL, 0 );
pElementText = new wchar_t[nTextLen + 1];
memset(( void* )pElementText, 0, sizeof( wchar_t ) * ( nTextLen + 1 ) );
::MultiByteToWideChar(CP_ACP, 0, strSrc, -1, pElementText, nTextLen);
wstring sText;
sText = pElementText;
delete[] pElementText;
return sText;
}
GBK转utf-8,宽字符转窄字符的更多相关文章
- 宽字符转窄字符CW2AEX<>(szAreaInfo,CP_UTF8)
CString szAreaInfo; CW2AEX<>(szAreaInfo,CP_UTF8); 最好能像上面这样转换,否则汉字就会转成乱码.
- 宽字符wchar_t和窄字符char——putwchar、wprintf
宽字符wchar_t 与 窄字符char 先说下窄字符char,这个大部分读者应该很清楚,char类型的变量占一个字节(byte)(也就是8个bit(比特)),能表示256个字符,那char的范围有两 ...
- C++ 宽字符(wchar_t)与窄字符(char)的转换
了解 长度 宽字符wchar_t的长度16位,可以用来显示中文等除英文外的其他文字, 窄字符 char 的长度 8 位,只能处理英文. 哪里可以见到 在VS2010, 2012, 2013 ...
- volatile,可变参数,memset,内联函数,宽字符窄字符,国际化,条件编译,预处理命令,define中##和#的区别,文件缓冲,位域
1.volatile: 要求参数修改每次都从内存中的读取.这种情况要比普通运行的变量需要的时间长. 当设置了成按照C99标准运行之后,使用volatile变量之后的程序运行的时间将比register的 ...
- C语言小程序——推箱子(窄字符和宽字符)
C语言小程序——推箱子(窄字符Version) 推箱子.c #include <stdio.h> #include <conio.h> #include <stdlib. ...
- 宽字符wchar_t和窄字符char区别和相互转换
转自:http://blog.csdn.net/nodeathphoenix/article/details/7416725 1. 首先,说下窄字符char了,大家都很清楚,就是8bit表示的b ...
- 关于MultiByteToWideChar与WideCharToMultiByte代码测试(宽字符与多字节字符的转换)以及字符串的转换代码测试
#pragma once #include <stdio.h> //getchar() #include <tchar.h> #include <stdlib.h> ...
- Spark --【宽依赖和窄依赖】
前言 Spark中RDD的高效与DAG图有着莫大的关系,在DAG调度中需要对计算过程划分stage,暴力的理解就是stage的划分是按照有没有涉及到shuffle来划分的,没涉及的shuffle的都划 ...
- Spark 中的宽依赖和窄依赖
Spark中RDD的高效与DAG图有着莫大的关系,在DAG调度中需要对计算过程划分stage,而划分依据就是RDD之间的依赖关系.针对不同的转换函数,RDD之间的依赖关系分类窄依赖(narrow de ...
随机推荐
- chromedriver bug
https://github.com/FuckTheWorld/chromedriver/issues/1145 https://bugs.chromium.org/p/chromedriver/is ...
- 2016 Multi-University Training Contest 5&6 总结
第五场和第六场多校都打得很糟糕. 能做到不以物喜不以己悲是假的,这对队伍的情绪也可以算上是比较大的打击. 很多时候我们发现了问题,但是依旧没有采取有效的方法去解决它,甚至也没有尝试去改变.这是一件相当 ...
- openNebula rgister img instance vms error collections
1, 注册镜像报错信息 ERROR="Fri Nov 21 12:57:17 2014 : Error copying image in the datastore: Not allowed ...
- Image editing techniques and algorithms using Qt
费了好半天劲先翻译这一点.还有好多地方不明白.先弄明白这一点.继续以后的翻译. 这一篇文章我们将讨论不同的技术和算法来修改图像使用Qt.但是在这之前我们继续你必须知道一些原则处理图片. 这里主要有两种 ...
- 君子性非异也,善假于物也 - Threejs 引入TrackballControls 查看场景
君子性非异也,善假于物也 - Threejs 引入TrackballControls 查看场景 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循" ...
- 菜鸟初试水--JQuery基础
此文仅作入门级文章,望大神们高抬贵手! JQuery: 它是一套跨浏览器的JavaScript库,简化HTML与JavaScript之间的操作. JQuery的用途: ①访问和操作DOM元素: 使用j ...
- events模块
/** * Created by Administrator on 2016/8/3. */ var http = require("http"); //Node 导入文件系统模块 ...
- gdb 命令使用
1.gdb -x command.txt 每次重复输入命令很麻烦,可以使用上面的命令,把命令输入进command.txt里面,然后直接就可以执行gdb. 2.list 2.1 list functio ...
- firebreath注册接口
对firebreath文档进行翻译,顺便做个笔记,原地址:http://www.firebreath.org/display/documentation/JSAPIAuto 综述: 你可能会对需要转换 ...
- apache rewrite rule
http://10.58.104.19:8008/site/833/3f11d2b44b7d3baa2149f26a30f8c68d/b.js?siteid=332323 将一个静态请求转换成一个动态 ...