编码转换函数
来源:互联网 发布:docker swarm 网络 编辑:程序博客网 时间:2024/05/19 20:18
忘了哪儿的!!
#ifdef _WIN32
#include "Windows.h"
#include <string>
{
int len = 0;
len = str.length();
int unicodeLen = ::MultiByteToWideChar( CP_ACP,
0,
str.c_str(),
-1,
NULL,
0 );
wchar_t * pUnicode;
pUnicode = new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
::MultiByteToWideChar( CP_ACP,
0,
str.c_str(),
-1,
(LPWSTR)pUnicode,
unicodeLen );
wstring rt;
rt = ( wchar_t* )pUnicode;
delete pUnicode;
return rt;
}
string UnicodeToANSI( const wstring& str )
{
char* pElementText;
int iTextLen;
// wide char to multi char
iTextLen = WideCharToMultiByte( CP_ACP,
0,
str.c_str(),
-1,
NULL,
0,
NULL,
NULL );
pElementText = new char[iTextLen + 1];
memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );
::WideCharToMultiByte( CP_ACP,
0,
str.c_str(),
-1,
pElementText,
iTextLen,
NULL,
NULL );
string strText;
strText = pElementText;
delete[] pElementText;
return strText;
}
wstring UTF8ToUnicode( const string& str )
{
int len = 0;
len = str.length();
int unicodeLen = ::MultiByteToWideChar( CP_UTF8,
0,
str.c_str(),
-1,
NULL,
0 );
wchar_t * pUnicode;
pUnicode = new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
::MultiByteToWideChar( CP_UTF8,
0,
str.c_str(),
-1,
(LPWSTR)pUnicode,
unicodeLen );
wstring rt;
rt = ( wchar_t* )pUnicode;
delete pUnicode;
return rt;
}
string UnicodeToUTF8( const wstring& str )
{
char* pElementText;
int iTextLen;
// wide char to multi char
iTextLen = WideCharToMultiByte( CP_UTF8,
0,
str.c_str(),
-1,
NULL,
0,
NULL,
NULL );
pElementText = new char[iTextLen + 1];
memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );
::WideCharToMultiByte( CP_UTF8,
0,
str.c_str(),
-1,
pElementText,
iTextLen,
NULL,
NULL );
string strText;
strText = pElementText;
delete[] pElementText;
return strText;
}
#endif
0 0
- 编码转换函数
- PHP编码转换函数
- PHP编码转换函数
- 字符编码转换函数
- PHP编码转换函数
- AS3 编码转换函数
- PHP编码转换函数
- 编码转换函数
- delphi7转换编码函数
- 编码转换函数
- 编码转换函数
- php编码转换函数
- UTF-8编码转换函数
- iconv 函数字符编码转换
- C++字符串编码转换函数
- php编码转换函数介绍
- php编码转换函数介绍
- 常用字符编码转换函数
- (转)如何在Eclipse中查看JDK类库的源代码
- Sping Security-授权
- Swift语言迈出侵蚀Androidd第一步
- 《秘密》卷一:秘密-秘密的发现
- 【Android】获取手机中已安装apk文件信息(PackageInfo、ResolveInfo)(应用图片、应用名、包名等)
- 编码转换函数
- 代码插入测试
- MYSQL: Cannot delete or update a parent row: a foreign key constraint fails
- codelity刷题---MinAvgTwoSlice
- Nginx-openresty+mysql+redis使用篇(一)
- Package manager has died at android.app.ApplicationPackageManager.getInstalledPackages
- <11>Android HAL 处理硬件设备访问权限问题
- 有关get_global/local_id/size
- 【UML之用例图】