如何将ascii 字符串以 UTF-8显示,跟帖有分
如何将ascii 字符串以 UTF-8显示:比如
<r><codesave u="200089350"><c type ="2"><fashion style="1" sex="0" suit="0" bg="159" recommend="0" optype="0" goodsNo="0"><item x="0" y="0" scale="1" res="mood_5.swf"/><item res="hairback_375.swf" x="159" y="-13" scale="2"/><item res="pants_375.swf" x="159" y="-13" scale="2"/><item res="coat_375.swf" x="159" y="-13" scale="2"/><item res="neck_2.swf" x="159" y="-13" scale="2"/><item res="face_2.swf" x="159" y="-13" scale="2"/><item res="earbob_46.swf" x="159" y="-13" scale="2"/><item res="hair_375.swf" x="159" y="-13" scale="2"/><item res="scene_70.swf" x="0" y="0" scale="1"/><item x="0" y="0" scale="1" res="mooddiary_5.swf"/><item x="1" y="35" scale="1" res="char_0.swf" mood="_瀹嬩綋_16_0xff0000_0_0_鎴戞檿鍟妐weqw鏄笉"/><item res="notice_0.swf" x="0" y="0" scale="1"/></fashion></c></codesave></r>
这段代码 以utf-8编码就可以再文本中显示了
如
<r><codesave u="200089350"><c type ="2"><fashion style="1" sex="0" suit="0" bg="159" recommend="0" optype="0" goodsNo="0"><item x="0" y="0" scale="1" res="mood_5.swf"/><item res="hairback_375.swf" x="159" y="-13" scale="2"/><item res="pants_375.swf" x="159" y="-13" scale="2"/><item res="coat_375.swf" x="159" y="-13" scale="2"/><item res="neck_2.swf" x="159" y="-13" scale="2"/><item res="face_2.swf" x="159" y="-13" scale="2"/><item res="earbob_46.swf" x="159" y="-13" scale="2"/><item res="hair_375.swf" x="159" y="-13" scale="2"/><item res="scene_70.swf" x="0" y="0" scale="1"/><item x="0" y="0" scale="1" res="mooddiary_5.swf"/><item x="1" y="35" scale="1" res="char_0.swf" mood="_宋体_16_0xff0000_0_0_我晕啊qweqw是不"/><item res="notice_0.swf" x="0" y="0" scale="1"/></fashion></c></codesave></r>
[最优解释]
上一个不错的转换函数
void Convert(const char* strIn,char* strOut, int sourceCodepage, int targetCodepage)
{
int len=lstrlen(strIn);
int unicodeLen=MultiByteToWideChar(sourceCodepage,0,strIn,-1,NULL,0);
wchar_t* pUnicode;
pUnicode=new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
MultiByteToWideChar(sourceCodepage,0,strIn,-1,(LPWSTR)pUnicode,unicodeLen);
BYTE * pTargetData = NULL;
int targetLen=WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)pTargetData,0,NULL,NULL);
pTargetData=new BYTE[targetLen+1];
memset(pTargetData,0,targetLen+1);
WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)pTargetData,targetLen,NULL,NULL);
lstrcpy(strOut,(char*)pTargetData);
delete pUnicode;
delete pTargetData;
}
[其他解释]
CStringA strA="mood="_瀹嬩綋_16_0xff0000_0_0_鎴戞檿鍟妐weqw鏄笉"";
CString strB=CA2CT(strA,CP_UTF8);
AfxMessageBox(strB);
[其他解释]
CStringA strA="mood="_瀹嬩綋_16_0xff0000_0_0_鎴戞檿鍟妐weqw鏄笉"";
CString strB=CA2CT(strA,CP_UTF8);
CString strC=CA2CT(CT2CA(strB,CP_UTF8));
AfxMessageBox(strB);
AfxMessageBox(strC);
[其他解释]
"mood="_瀹嬩綋_16_0xff0000_0_0_鎴戞檿鍟妐weqw鏄笉"";
是MBCS 不是什么 “ascii 字符串”
[其他解释]
1,mbcs 到 unicode
2,unicode 到 utf8
[其他解释]
感谢两位啦
[其他解释]