MFC中如何将\u4e91\u8bfe\u5802编码转换成中文?
答案:2 悬赏:10 手机版
解决时间 2021-03-20 23:58
- 提问者网友:难遇难求
- 2021-03-20 09:36
MFC中如何将\u4e91\u8bfe\u5802编码转换成中文?
最佳答案
- 五星知识达人网友:玩家
- 2021-03-20 10:15
直接转成UTF8格式就行了。
我给你个函数:
UTF-8与UNICODE相互转换的代码:
int32 UnicodeToUTF8(const oscl_wchar *szSrc, int32 nSrcLen, char *strDest, int32 nDestLen)
{
int32 i = 0;
int32 i_cur_output = 0;
char ch_tmp_byte;
if (nDestLen <= 0)
{
// We cannot append terminate string for this case.
return 0;
}
for (i = 0; i < nSrcLen; i++)
{
if (BYTE_1_REP > szSrc[i])
{
if (i_cur_output + 1 < nDestLen)
{
strDest[i_cur_output++] = (char)szSrc[i];
}
else
{
strDest[i_cur_output] = '\0';
return 0;
}
}
else if (BYTE_2_REP > szSrc[i])
{
if (i_cur_output + 2 < nDestLen)
{
strDest[i_cur_output++] = (char)(szSrc[i] >> 6 | 0xc0);
strDest[i_cur_output++] = (char)((szSrc[i] & 0x3f) | 0x80);
}
else
{
strDest[i_cur_output] = '\0';
return 0;
}
}
else if (SURROGATE_MAX > szSrc[i] && SURROGATE_MIN < szSrc[i])
{
if (i_cur_output + 4 < nDestLen)
{
ch_tmp_byte = (char)(((szSrc[i] & 0x3c0) >> 6) + 1);
strDest[i_cur_output++] = (char)(ch_tmp_byte >> 2 | 0xf0);
strDest[i_cur_output++] = (char)(((ch_tmp_byte & 0x03) | 0x80) | (szSrc[i] & 0x3e) >> 2);
}
else
{
strDest[i_cur_output] = '\0';
return 0;
}
}
else
{
if (i_cur_output + 3 < nDestLen)
{
strDest[i_cur_output++] = (char)(szSrc[i] >> 12 | 0xe0);
strDest[i_cur_output++] = (char)(((szSrc[i] >> 6) & 0x3f) | 0x80);
strDest[i_cur_output++] = (char)((szSrc[i] & 0x3f) | 0x80);
}
else
{
strDest[i_cur_output] = '\0';
return 0;
}
}
}
strDest[i_cur_output] = '\0';
return i_cur_output;
我给你个函数:
UTF-8与UNICODE相互转换的代码:
int32 UnicodeToUTF8(const oscl_wchar *szSrc, int32 nSrcLen, char *strDest, int32 nDestLen)
{
int32 i = 0;
int32 i_cur_output = 0;
char ch_tmp_byte;
if (nDestLen <= 0)
{
// We cannot append terminate string for this case.
return 0;
}
for (i = 0; i < nSrcLen; i++)
{
if (BYTE_1_REP > szSrc[i])
{
if (i_cur_output + 1 < nDestLen)
{
strDest[i_cur_output++] = (char)szSrc[i];
}
else
{
strDest[i_cur_output] = '\0';
return 0;
}
}
else if (BYTE_2_REP > szSrc[i])
{
if (i_cur_output + 2 < nDestLen)
{
strDest[i_cur_output++] = (char)(szSrc[i] >> 6 | 0xc0);
strDest[i_cur_output++] = (char)((szSrc[i] & 0x3f) | 0x80);
}
else
{
strDest[i_cur_output] = '\0';
return 0;
}
}
else if (SURROGATE_MAX > szSrc[i] && SURROGATE_MIN < szSrc[i])
{
if (i_cur_output + 4 < nDestLen)
{
ch_tmp_byte = (char)(((szSrc[i] & 0x3c0) >> 6) + 1);
strDest[i_cur_output++] = (char)(ch_tmp_byte >> 2 | 0xf0);
strDest[i_cur_output++] = (char)(((ch_tmp_byte & 0x03) | 0x80) | (szSrc[i] & 0x3e) >> 2);
}
else
{
strDest[i_cur_output] = '\0';
return 0;
}
}
else
{
if (i_cur_output + 3 < nDestLen)
{
strDest[i_cur_output++] = (char)(szSrc[i] >> 12 | 0xe0);
strDest[i_cur_output++] = (char)(((szSrc[i] >> 6) & 0x3f) | 0x80);
strDest[i_cur_output++] = (char)((szSrc[i] & 0x3f) | 0x80);
}
else
{
strDest[i_cur_output] = '\0';
return 0;
}
}
}
strDest[i_cur_output] = '\0';
return i_cur_output;
全部回答
- 1楼网友:七十二街
- 2021-03-20 10:20
是爷们的娘们的都帮顶!大力支持
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯