格式转换1
来源:互联网 发布:淘宝流量充多少划算 编辑:程序博客网 时间:2024/05/16 20:30
using namespace std;
class Convert
{
public:
static wstring string2wstring(const string& s)
{
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}
static wstring ANSIToUnicode( const string& str )
{
int 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 = ( wchar_t* )pUnicode;
delete pUnicode;
return rt;
}
static 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 = pElementText;
delete[] pElementText;
return strText;
}
static wstring UTF8ToUnicode( const string& str )
{
int 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 = ( wchar_t* )pUnicode;
delete pUnicode;
return rt;
}
static 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 = pElementText;
delete[] pElementText;
return strText;
}
};
class Convert
{
public:
static wstring string2wstring(const string& s)
{
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
}
static wstring ANSIToUnicode( const string& str )
{
int 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 = ( wchar_t* )pUnicode;
delete pUnicode;
return rt;
}
static 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 = pElementText;
delete[] pElementText;
return strText;
}
static wstring UTF8ToUnicode( const string& str )
{
int 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 = ( wchar_t* )pUnicode;
delete pUnicode;
return rt;
}
static 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 = pElementText;
delete[] pElementText;
return strText;
}
};
- 格式转换1
- ToString格式转换大全(1)
- 格式转换
- 格式转换
- 格式转换
- 格式转换
- 格式转换
- 格式转换
- 格式转换
- 格式转换
- 格式转换
- 格式转换
- 格式转换
- 格式转换
- GPS 经纬度数据 格式转换1
- 时间格式转换公共类1
- socket网络编程(1):格式转换函数
- (1)转换字符串格式:1233422222-》1121324125
- java 去前导0
- 最大子序列和的问题
- vim小技巧(将Caps Lock键映射成Esc)
- 《Python核心编程》中文第二版课后练习3.8答案
- linux c 多线程编程
- 格式转换1
- device importent address
- 简单聊天室
- Servlet和JSP的生命周期
- linux带缓冲IO操作与不带缓冲IO操作
- C语言库排序
- 【 解 析 面 向 对 象 编 程 的 特 点 】 之 【 多 态 】
- Win 7下运用diskpart.exe删除额外的100MB系统保留区or创建逻辑分区
- C# 三层架构