关于ANSI和Unicode、Unicode和UTF-8等的相互转换
2013-10-16 10:03
274 查看
关于ANSI和Unicode、Unicode和UTF-8等的相互转换可通用的代码如下:
qp::StringW Global::AnsiToUnicode(
const
char
* buf)
{
int
len = ::MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
if
(len == 0)
return
L
""
;
std::vector<</CODE>wchar_t
> unicode(len);
::MultiByteToWideChar(CP_ACP, 0, buf, -1, &unicode[0], len);
return
&unicode[0];
}
qp::StringA Global::UnicodeToAnsi(
const
wchar_t
* buf)
{
int
len = ::WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL);
if
(len == 0)
return
""
;
std::vector<</CODE>char
> utf8(len);
::WideCharToMultiByte(CP_ACP, 0, buf, -1, &utf8[0], len, NULL, NULL);
return
&utf8[0];
}
qp::StringW Global::Utf8ToUnicode(
const
char
* buf)
{
int
len = ::MultiByteToWideChar(CP_UTF8, 0, buf, -1, NULL, 0);
if
(len == 0)
return
L
""
;
std::vector<</CODE>wchar_t
> unicode(len);
::MultiByteToWideChar(CP_UTF8, 0, buf, -1, &unicode[0], len);
return
&unicode[0];
}
qp::StringA Global::UnicodeToUtf8(
const
wchar_t
* buf)
{
int
len = ::WideCharToMultiByte(CP_UTF8, 0, buf, -1, NULL, 0, NULL, NULL);
if
(len == 0)
return
""
;
std::vector<</CODE>char
> utf8(len);
::WideCharToMultiByte(CP_UTF8, 0, buf, -1, &utf8[0], len, NULL, NULL);
return
&utf8[0];
}
相关文章推荐
- 关于Unicode&UTF-8&ANSI的相互转换(Ver1.1)
- ansi unicode utf-8相互转换
- ANSI,UNICODE, UTF-8 字符串之间的相互转换
- 关于JAVA字符编码:Unicode,ISO-8859-1,GBK,UTF-8编码及相互转换
- 关于JAVA字符编码:Unicode,ISO-8859-1,GBK,UTF-8编码及相互转换
- 关于JAVA字符编码:Unicode,ISO-8859-1,GBK,UTF-8编码及相互转换
- 关于JAVA字符编码:Unicode,ISO-8859-1,GBK,UTF-8编码及相互转换
- ANSI,UNICODE, UTF-8 字符串之间的相互转换
- ANSI、UNICODE、UTF-8编码格式相互之间转换
- unicode、utf-8、ansi的故事及其相互转换
- Ansi,Unicode(little endian),Unicode big endian,UTF-8编码文件相互转换
- unicode、utf-8、ansi的故事及其相互转换
- windows ASCII,UTF-8,Unicode字符串相互转换
- 关于编码ansi、GB2312、unicode与utf-8的区别
- 【JAVA编码】 JAVA字符编码系列二:Unicode,ISO-8859,GBK,UTF-8编码及相互转换
- 关于编码:ANSI, GBK, GB2312, UTF-8, GB18030, UNICODE
- PHP如何实现Unicode和Utf-8编码相互转换
- ANSI, UNICODE与UTF8相互转换模板类
- UTF-8,UNICODE,Gb2312他们3个之间的相互转换