| 发表于:2008-02-27 14:40:044楼 得分:0 |
gb2312的文字转换为utf-8这么转,代码如下: cstring cpostgoods::toutf8(cstring sourcestr,cstring targetstr) { //unicode to utf8 char *ptargetdata = null; int targetlen=widechartomultibyte(cp_utf8,0,(lpcwstr)sourcestr,-1,ptargetdata,0,null,null); ptargetdata = new char[targetlen+1]; memset(ptargetdata,0,targetlen+1); widechartomultibyte(cp_utf8,0,(lpcwstr)sourcestr,-1,ptargetdata,targetlen,null,null); char *data = ptargetdata; //utf8codelen int unicodelen=multibytetowidechar(cp_utf8,0,data,strlen(data)+1,null,0); unicodelen+=1; // a wide char string wchar_t *wszwidecharstring = null; wszwidecharstring = new wchar_t[unicodelen]; // convert the multy byte string to wide char string ::multibytetowidechar(cp_acp,0,data,strlen(data)+1,wszwidecharstring,unicodelen); // display the wide char string //afxmessagebox(wszwidecharstring); //output cstring result; result = wszwidecharstring; //afxmessagebox(result); //release delete []wszwidecharstring; wszwidecharstring = null; delete []ptargetdata; ptargetdata = null; return result; } | | |
|