vs2010字符串的转换
来源:互联网 发布:ios屏幕录像软件 编辑:程序博客网 时间:2024/06/12 00:31
void ConvertGBKToUtf8(std::string& strGBK)
{
int len=MultiByteToWideChar(CP_ACP, 0, (char*)strGBK.c_str(), -1, NULL,0);
wchar_t * wszUtf8 = new wchar_t[len+1];
memset(wszUtf8, 0, len * 2 + 2);
MultiByteToWideChar(CP_ACP, 0, (char*)strGBK.c_str(), -1, wszUtf8, len);
len = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, NULL);
char *szUtf8=new char[len + 1];
memset(szUtf8, 0, len + 1);
WideCharToMultiByte (CP_UTF8, 0, wszUtf8, -1, szUtf8, len, NULL,NULL);
strGBK = szUtf8;
delete[] szUtf8;
delete[] wszUtf8;
}
void ConvertUtf8ToGBK(std::string& strUtf8)
{
int len=MultiByteToWideChar(CP_UTF8, 0, (char*)strUtf8.c_str(), -1, NULL,0);
wchar_t * wszGBK = new wchar_t[len+1];
memset(wszGBK, 0, len * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0, (char*)strUtf8.c_str(), -1, wszGBK, len);
len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
char *szGBK=new char[len + 1];
memset(szGBK, 0, len + 1);
WideCharToMultiByte (CP_ACP, 0, wszGBK, -1, szGBK, len, NULL,NULL);
strUtf8 = szGBK;
delete[] szGBK;
delete[] wszGBK;
}
wstring ANSIToUnicode( const string& str )
{
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;
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;
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;
}
void wcharTochar(const wchar_t *wchar, char *chr, int length)
{
WideCharToMultiByte( CP_ACP, 0, wchar, -1,
chr, length, NULL, NULL );
}
char *GetBuf(CString str)
{
CString origCString=_T("");
origCString = str;
wchar_t* wCharString = origCString.GetBuffer(origCString.GetLength()+1);
size_t origsize = wcslen(wCharString) + 1;
size_t convertedChars = 0;
char *CharString;
CharString=(char*)malloc(origsize);
wcharTochar(wCharString,CharString,origsize);
return CharString;
}
- vs2010字符串的转换
- VS2010下 字符串各进制之间的转换
- VS2013与VS2010的转换
- VS2013与VS2010的转换
- VS2010字符串相加的问题
- 如何在各种字符串类型之间进行转换(VS2010)
- VS2010/MFC将字符串类型转换为char类型
- VS2010 VS2005 VS2008工程之间的转换
- VS2003转换到VS2010的记录
- vs2005 vs2008 vs2010间工程的转换
- VS2013源码转换VS2010的解决方法
- VS2010配置连接远程数据库的字符串
- 字符串之间的转换
- 整数字符串的转换
- 字符串的相互转换
- 字符串之间的转换
- 字符串之间的转换
- 字符串的双向转换
- pdf阅读器开发
- 素数判定 费马测试
- android 短信sms 接入,实现短信验证注册功能
- C++ primer 第五版习题答案, Stanley B. Lippman( 斯坦利 李普曼)(持续更新中)
- 私户银行卡送礼洗钱出售
- vs2010字符串的转换
- Difference Between == and === : A Simple Comparison
- IOS开发笔记 术语篇
- 二叉树后序遍历的两种非递归实现思路
- pthread_cond_wait()使用、执行过程及一些问题
- IOS开发笔记 框架篇
- Dojo与jQuery综合比较分析
- sql server语句中日期时间格式化查询
- 反转带头结点的链表