导航条上的链接 怎么都倒过来了?难道是我把utf 16 gb23122换成了utf-8?

我把.html文件改成GB2312了,又改回来了,UTF-8,全成乱码了怎么解决啊?_百度知道
我把.html文件改成GB2312了,又改回来了,UTF-8,全成乱码了怎么解决啊?
我有更好的答案
这个你直接改变代码上的编辑语言就会出现乱码的。我一般改的方法如下:比如把一个GB2312文件改为UFT-81.在DW中新建一个UTF-8的HTML文档2.用记事本打开GB2312的HTML文档,复制全部代码3.粘贴到UTF-8的HTML中4.保存即可。
那我的整不回来了,是吧
已成乱码了,当然就无能为力了。
为您推荐:
其他类似问题
utf的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。UTF-8怎么转换成GB2312_百度知道
UTF-8怎么转换成GB2312
我有更好的答案
如果只有一两个文件,用记事本打开UTF8文件,然后保存,保存时点击“保存选项”按钮,选择文件格式为ANSI,在中文Windows环境下,这个新文件就是GB2312格式的了。
采纳率:92%
来自团队:
为您推荐:
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。UTF-8与GB2312之间的互换 - pengyingh - 博客园
http://www.vckbase.com/document/viewdoc/?id=1397
相信一定有不少的程序开发人员时常会遇到字符编码的问题,而这个问题也是非常让人头痛的。因为这些都是潜在的错误,要找出这些错误也得要有这方面的开发经验才行。特别是在处理xml文档时 ,该问题的出现就更加的频繁了,有一次用java写服务器端程序,用vc写客户端与之交互。交互的协议都是用xml写的。结果在通讯时老是发现数据接受不正确。纳闷!于是用抓取网络数据包工具抓取数据,后来才发现原来是java上xml的头是这样的&?xml version="1.0" encoding="UTF-8"?&,而vc上默认的是GB2312。所以一遇到汉字数据就不正确了。去网上找资料,这方面的文章好象特别少,针对像这样的问题,下面我介绍一下我自己写的一个转换程序。当然,程序很简单。如果有画蛇添足的地方,还望各位高手一笑了之。  如果您对UTF-8、Unicode、GB2312等还是很陌生的话,请查看,我这里就不浪费口舌了。下面介绍一下WinAPI的两个函数:WideCharToMultiByte、MultiByteToWideChar。函数原型:
int WideCharToMultiByte(
UINT CodePage, // code page
DWORD dwFlags, // performance and mapping flags
LPCWSTR lpWideCharStr, // wide-character string
int cchWideChar, // number of chars in string
LPSTR lpMultiByteStr, // buffer for new string
int cbMultiByte, // size of buffer
LPCSTR lpDefaultChar, // default for unmappable chars
LPBOOL lpUsedDefaultChar // set when default char used
); //将宽字符转换成多个窄字符
int MultiByteToWideChar(
UINT CodePage, // code page
DWORD dwFlags, // character-type options
LPCSTR lpMultiByteStr, // string to map
int cbMultiByte, // number of bytes in string
LPWSTR lpWideCharStr, // wide-character buffer
int cchWideChar // size of buffer
);//将多个窄字符转换成宽字符
需要用到的一些函数:
CString CXmlProcess::HexToBin(CString string)//将16进制数转换成2进制
if( string == "0") return "0000";
if( string == "1") return "0001";
if( string == "2") return "0010";
if( string == "3") return "0011";
if( string == "4") return "0100";
if( string == "5") return "0101";
if( string == "6") return "0110";
if( string == "7") return "0111";
if( string == "8") return "1000";
if( string == "9") return "1001";
if( string == "a") return "1010";
if( string == "b") return "1011";
if( string == "c") return "1100";
if( string == "d") return "1101";
if( string == "e") return "1110";
if( string == "f") return "1111";
return "";
CString CXmlProcess::BinToHex(CString BinString)//将2进制数转换成16进制
if( BinString == "0000") return "0";
if( BinString == "0001") return "1";
if( BinString == "0010") return "2";
if( BinString == "0011") return "3";
if( BinString == "0100") return "4";
if( BinString == "0101") return "5";
if( BinString == "0110") return "6";
if( BinString == "0111") return "7";
if( BinString == "1000") return "8";
if( BinString == "1001") return "9";
if( BinString == "1010") return "a";
if( BinString == "1011") return "b";
if( BinString == "1100") return "c";
if( BinString == "1101") return "d";
if( BinString == "1110") return "e";
if( BinString == "1111") return "f";
return "";
int CXmlProcess::BinToInt(CString string)//2进制字符数据转换成10进制整型
int len =0;
int tempInt = 0;
int strInt = 0;
for(int i =0 ;i & string.GetLength() ;i ++)
tempInt = 1;
strInt = (int)string.GetAt(i)-48;
for(int k =0 ;k & 7- k++)
tempInt = 2*tempI
len += tempInt*strI
  UTF-8转换成GB2312先把UTF-8转换成Unicode.然后再把Unicode通过函数WideCharToMultiByte转换成GB2312
WCHAR* CXmlProcess::UTF_8ToUnicode(char *ustart)
//把UTF-8转换成Unicode
char char_
char char_
char char_
char uchar[2];
CString string_
CString string_
CString string_
CString combiS
char_one = *
char_two = *(ustart+1);
char_three = *(ustart+2);
string_one.Format("%x",char_one);
string_two.Format("%x",char_two);
string_three.Format("%x",char_three);
string_three = string_three.Right(2);
string_two = string_two.Right(2);
string_one = string_one.Right(2);
string_three = HexToBin(string_three.Left(1))+HexToBin(string_three.Right(1));
string_two = HexToBin(string_two.Left(1))+HexToBin(string_two.Right(1));
string_one = HexToBin(string_one.Left(1))+HexToBin(string_one.Right(1));
combiString = string_one +string_two +string_
combiString = combiString.Right(20);
combiString.Delete(4,2);
combiString.Delete(10,2);
Hchar = BinToInt(combiString.Left(8));
Lchar = BinToInt(combiString.Right(8));
uchar[1] = (char)H
uchar[0] = (char)L
unicode = (WCHAR *)
char * CXmlProcess::UnicodeToGB2312(unsigned short uData)
//把Unicode 转换成 GB2312
buffer = new char[sizeof(WCHAR)];
WideCharToMultiByte(CP_ACP,NULL,&uData,1,buffer,sizeof(WCHAR),NULL,NULL);
  GB2312转换成UTF-8:先把GB2312通过函数MultiByteToWideChar转换成Unicode.然后再把Unicode通过拆开Unicode后拼装成UTF-8。
WCHAR * CXmlProcess::Gb2312ToUnicode(char *gbBuffer)
//GB2312 转换成 Unicode
WCHAR *uniC
uniChar = new WCHAR[1];
::MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,gbBuffer,2,uniChar,1);
return uniC
char * CXmlProcess::UnicodeToUTF_8(WCHAR *UniChar) // Unicode 转换成UTF-8
CString strO
CString strT
CString strT
CString strF
CString strA
buffer = new char[3];
int hInt,lI
hInt = (int)((*UniChar)/256);
lInt = (*UniChar)%256;
string.Format("%x",hInt);
strTwo = HexToBin(string.Right(1));
string = string.Left(string.GetLength() - 1);
strOne = HexToBin(string.Right(1));
string.Format("%x",lInt);
strFour = HexToBin(string.Right(1));
string = string.Left(string.GetLength() -1);
strThree = HexToBin(string.Right(1));
strAnd = strOne +strTwo + strThree + strF
strAnd.Insert(0,"1110");
strAnd.Insert(8,"10");
strAnd.Insert(16,"10");
strOne = strAnd.Left(8);
strAnd = strAnd.Right(16);
strTwo = strAnd.Left(8);
strThree = strAnd.Right(8);
*buffer = (char)BinToInt(strOne);
buffer[1] = (char)BinToInt(strTwo);
buffer[2] = (char)BinToInt(strThree);
例子:将GB2312转换成UTF-8的调用:
char * CXmlProcess::translateCharToUTF_8(char *xmlStream, int len)
int newCharLen =0 ;
int oldCharLen = 0;
int revCharLen =
char* newCharB
char* finalCharB
= new char[sizeof(WCHAR)];
newCharBuffer = new char[int(1.5*revCharLen)];//设置最大的一个缓冲区
while(oldCharLen & revCharLen)
if( *(xmlStream + oldCharLen) &= 0)
*(newCharBuffer+newCharLen) = *(xmlStream +oldCharLen);
newCharLen ++;
oldCharLen ++;
}//如果是英文直接复制就可以
WCHAR *pbuffer = this-&Gb2312ToUnicode(xmlStream+oldCharLen);
buffer = this-&UnicodeToUTF_8(pbuffer);
*(newCharBuffer+newCharLen) = *
*(newCharBuffer +newCharLen +1) = *(buffer + 1);
*(newCharBuffer +newCharLen +2) = *(buffer + 2);
newCharLen += 3;
oldCharLen += 2;
newCharBuffer[newCharLen] = ''\0'';
CString string1 ;
string1.Format("%s",newCharBuffer);
finalCharBuffer = new char[newCharLen+1];
memcpy(finalCharBuffer,newCharBuffer,newCharLen+1);
return finalCharB
/*字符串编码转换&GBK&to&UTF8&(ansi版)*/char&*gbk2utf8(const&char&*strGBK){int&wchar_t&*strUchar&*strUTF8;if&(!strGBK){return&NULL;}len&=&MultiByteToWideChar(CP_GBK,&0,strGBK,&-1,&NULL,0);if&(len&&1){return&NULL;}strUnicode&=&(wchar_t&*)&malloc(sizeof(wchar_t)&*&len);if&(!strUnicode){return&NULL;}len&=&MultiByteToWideChar(CP_GBK,&0,&strGBK,&-1,&strUnicode,&len);if&(len&1){free(strUnicode);return&NULL;}len&=&WideCharToMultiByte(CP_UTF8,&0,&strUnicode,&-1,&NULL,&0,&NULL,&NULL);if&(len&1){free(strUnicode);return&NULL;}strUTF8&=&(char&*)&malloc(sizeof(char)&*&len);if&(!strUTF8){free(strUnicode);return&NULL;}len&=&WideCharToMultiByte&(CP_UTF8,&0,&strUnicode,&-1,&strUTF8,&len,&NULL,NULL);free(strUnicode);if&(len&1){free(strUTF8);return&NULL;}return&strUTF8;} ( xmwen 发表于
19:38:00)&&[&原创文档&本文适合中级读者&已阅读34485次&]搞笑,这种害人害己的文章还有这么多人访问。作者光知道&WideCharToMultiByte&可以把&Unicode&转成&GB2312&就不知道也可以把&Unicode&转换为&UTF-8&吗?其实这是一个很简单的程序,都被作者搞复杂了。要实现&GB2312&(其实是GBK)转换为&UTF-8&其实很简单,先用&MultiByteToWideChar&把&GB2312&转换为&Unicode,再用&WideCharToMultiByte&把&Unicode&转换为&UTF-8&就可以了。UTF-8&转换为&GB2312&是个相反的过程,先用&MultiByteToWideChar&把&UTF-8&转换为&Unicode,再用&WideCharToMultiByte&把&Unicode&转换为&GB2312&就可以了。 ( 雁过留声 发表于
9:11:00)&&translateCharToUTF_8的编码不对,请作者检查一下,如:&"你是我的好朋友"转换成了;"浣犳槸鎴戠殑濂芥i脲弸鍚?"正确的应是:"浣犳槸鎴戠殑濂芥湅鍙嬪悧"对于有的编码还能对...交流一下:kudoo.( kudoo 发表于
19:46:00)&&shines在,提供了一段程序,里面有buffersize&=&WideCharToMultiByte(CP_UTF8,&MB_PRECOMPOSED,&unicode,&wide_size,&NULL,&0,&NULL,&0);&&&&buffer&=&new&char[buffersize+1];但是,我在调试的时候发现:buffersize似乎已经预先留了&\0&的位置,或者是不是我出错了比如:&i&love&you,爱&GB2312是需要14个字节UTF8是需要15个字节,返回时候就是这些了啊,我的地址是:robin-,谁能回答以下,感谢!! ( robin_fox_nan 发表于
20:20:00)&&晕.格式没有了原文请看http://www.kbadboy.com/viewfull.asp?id=33 ( 鬼龙之舞 发表于
16:13:00)&&支持楼主!是因为你我才写出来的,不管是在体积还是在速度,相信都比楼主的强一点,如果不考虑移植性的话感谢楼主!!UTF8toUnicode&proc&uses&esi&edi&lpszBuf_OUT,lpszUTF8_INmov&esi,lpszUTF8_INmov&edi,lpszBuf_OUT.while&TRUE&mov&al,[esi].if&sbyte&ptr&al&&0mov&al,[esi]and&al,bshl&al,4mov&[edi+1],almov&al,[esi+1]and&al,bshr&al,2or&[edi+1],almov&al,[esi+1]and&al,11bshl&al,6mov&[edi+0],almov&al,[esi+2]and&al,bor&&[edi+0],aladd&edi,2add&esi,3.elseif&alxor&ah,ahstoswinc&esi.elsemov&WORD&ptr&[edi],0.break.endif.endwretUTF8toUnicode&endp ( 鬼龙之舞 发表于
16:11:00)&&UnicodetoUTF8&proc&&uses&esi&edi&lpBuf_OUT,lpszUTF8_INmov&esi,lpszUTF8_INmov&edi,lpBuf_OUT.while&TRUE&mov&ax,[esi].if&ax==0stosw.break.elseif&ah==0add&esi,2stosw.elsemov&al,[esi+1]shr&al,4or&&al,bmov&[edi+0],almov&al,[esi+1]and&al,bshl&al,2or&&al,bmov&ah,[esi+0]shr&ah,6or&&al,ahmov&[edi+1],almov&al,[esi+0]and&al,bor&&al,bmov&[edi+2],aladd&edi,3add&esi,2.endif.endwretUnicodetoUTF8&endp ( 鬼龙之舞 发表于
16:11:00)&&帮忙弄以下 ( zztop5384 发表于
10:35:00)&&int&WideCharToMultiByte(UINT&CodePage,&//&code&pageDWORD&dwFlags,&//&performance&and&mapping&flagsLPCWSTR&lpWideCharStr,&//&wide-character&stringint&cchWideChar,&//&number&of&chars&in&stringLPSTR&lpMultiByteStr,&//&buffer&for&new&stringint&cbMultiByte,&//&size&of&bufferLPCSTR&lpDefaultChar,&//&default&for&unmappable&charsLPBOOL&lpUsedDefaultChar&//&set&when&default&char&used);&//将宽字符转换成多个窄字符这些只是函数原型,并没有具体实现 ( zztop5384 发表于
10:27:00)&&//对不起,少加了个扩号WCHAR*&CXmlProcess::UTF_8ToUnicode(char&*pText){char&uchar[2];WCHAR&*char_one&=&pText[0];char_two&=&pText[1]);char_three&=&pText[2];uchar[1]&=&((pText[0]&&&0x0F)&&&&4)&+&((pText[1]&&&&2)&&&0x0F);uchar[0]&=&((pText[1]&&&0x03)&&&&6)&+&(pText[2]&&&0x3F);unicode&=&(WCHAR&*)return&}( Mycro 发表于
&zyl910:从Wndows2000开始,Windows系统就支持了UTF-8代码页65001(甚至还支持UTF-7&&65000)先使用代码页65001调用MultiByteToWideChar将UTF-8转为UTF-16LE(Windows中的Unicode字符串实际上是UTF-16LE)再使用代码页936调用WideCharToMultiByte将UTF-16LE字符串转为GB2312字符串CP_ACP是指系统代码页只有在&中文(中国)&的时候CP_ACP才等价与GB2312所以在必需转成GB2312时必须写清楚936从Windows98开始代码页936不再指GB而是GBK&&GB2312扩展GBK的收录了2万多字,简体繁体都有(GB的字汇范围)现在最新的汉子标准是GB允许4字节编码的汉字所以编码空间是260万足够收录所有汉字但是只有WindowsXP(及以上,如Windows&Server&2003)才在内核上支持GB(Win2000需要打补丁)GB的代码页是54936(发表于 9:31:00)&wuhuaqiang:什么都别说了,换一份工作吧;写文章的事情不着急。看过你的另一篇ftp断点续传的文章,学到了一些东西。(发表于 10:20:00)&sllihui:请作者贴出UTF-8转换成GB2312的实现函数。谢谢。我截获网页数据包。可以通过这种办法将乱码转成汉字吗??(发表于 13:24:00)&shines:&&&&char&*buffer&=&NULL;&&&&int&&&&&buffersize&=&WideCharToMultiByte(CP_UTF8,&MB_PRECOMPOSED,&unicode,&wide_size,&NULL,&0,&NULL,&0);&&&&buffer&=&new&char[buffersize+1];&&&&BOOL&bUsedDefaultChar&=&FALSE;&&&&int&sizeUTF&=&WideCharToMultiByte(CP_UTF8,&MB_PRECOMPOSED,&unicode,&wide_size,&&&&&&&&buffer,&buffersize+1,&&&&&&&&NULL,&NULL);&&&&if&(sizeUTF&!=&0)&&&&{&&&&&&&&buffer[sizeUTF]&=&0;&&&&&&&&strUTF&=&&&&&&&&&bSuccess&=&&&&&}&&&&else&&&&{&&&&&&&&strUTF&=&_T("");&&&&&&&&bSuccess&=&&&&&}&&&&delete[]&&&&&delete[]&&&&&delete[]&byteA&&&&return&bS}(发表于 17:19:00)&shines:bool&ConvGB2312ToUTF8(CString&strGB2312,&CString&&strUTF){&&&&int&nLength&=&strGB2312.GetLength();&&&&bool&bSuccess&=&&&&&if&(nLength&==&0)&&&&{&&&&&&&&strUTF&=&_T("");&&&&&&&&return&&&&&}&&&&int&nByteLength&=&nLength&+&1;&&&&char&*byteArray&=&NULL;&&&&byteArray&=&new&char[nByteLength];&&&&if&(byteArray&==&NULL)&&&&&&&&return&&&&&strcpy(byteArray,&(LPCTSTR)strGB2312);&&&&wchar_t&*unicode&=&NULL;&&&&int&uni_&&&&uni_size&=&MultiByteToWideChar(LANG_CP_GB2312,&0,&byteArray,&nLength,&NULL,&0);&&&&unicode&=&new&wchar_t[uni_size+1];&&&&int&wide_size&=&MultiByteToWideChar(LANG_CP_GB2312,&0,&byteArray,&nLength,&unicode,&uni_size+1);&&&&unicode[wide_size]&=&0;&&&&if&(wide_size&==&0)&&&&{&&&&&&&&delete[]&&&&&&&&&return&&&&&}(发表于 17:19:00)&shines:UTF-8就是专门手机这种嵌入式设备的新的编码法,他的特点是,传统的ASCII字符还是以一个字&&&&节来表示的,但是如果字符不属于ASCII字符集时,就用两至三个位来表示。&&&&&&在&0xF之间的字符(传统的ASCII字符)用一个位来表示&&&&&&&&&0&|&bits0-6&&&&&&在&0x000以及在0xFF之间的字符使用下面来表示:&&&&&&&&&1&|&1&|&0&|&bits&6-10&|&1&|&0&|&bits&0-5&&&&&&如果虚拟机看到这样的一个字符的话,虚拟机会把第一个字节最前头的110以及第二个字节的前头&&&&&&的10拿掉把剩下的位重新组合成一个2字节的数位来表示字符:&&&&&&&&&00000&|&bits&6-10&|&bits&0-5&&&&&&同理,0x0800&-&0xFFFF的字符表示:&&&&&1&|&1&|&1&|&0&|&bits&12-15&|&1&|&0&|&bits&6-11&|&1&|&0&|&bits&&0-5&&&&&&也可以用同样的方法重新组合成一个两个字节的字符串来&&&&&&特别需要注意的是kjava中的null字符也使用两个字节来表示而不是一个字节:)******************************************************************************/(发表于 17:21:00)&shines:/*****************************************************************************&&&&手机里面的字符串基本上都是采用的UTF-8的编码法。&&&&而我们在PC机器上所采用的基本上都是ASCII和unicode编码法&&&&ASCII编码法是单字节的编码方法,只能表示256个字符,英文字母是足够了&&&&但是无法表示汉字&&&&unicode是双字节的编码法,可以用来表示汉字,但是却对于一般的英文字母浪费了太多的空间&&&&(至少面对于手机的存储是这样的)。(发表于 17:21:00)&shines:贴一个我自己写的GB2312转UTF8的函数,也许比楼主的简单一些,如果是要转换成&#xFFFF的格式那种的话,则需要另外写,其实&#xFFFF中的&"FFFF"&就是Unicode的十六进制表示。这里的UTF8编码方式,与Java的InputStream.WriteUTF()的编码方式一致。由于评论只能贴1000个字,所以采取这种倒贴的方式,请见谅,大家合起来看吧(发表于 17:23:00)&shines:另外补充一下,我的程序也许只能在Win2000、WinNT以后(XP,Win2003等)的系统工作,Win98下是否可以没有试过,这年头很少用这个系统了(发表于 17:27:00)&Mycro:谁知道Unix下,除了ICU,还有什么更简单的办法?我不想用XML4C来搞。。(发表于 21:48:00)&hryyx:强烈建议作者贴出UTF-8转换成GB2312的实现函数。谢谢。否则文章与题目就不符了,UTF-8与GB2312之间的&互换&(发表于 10:48:00)&CodeStylite:// LPSTR str&=&"浠嬬粛";LPSTR str&=&new&char[14];BYTE a[]&= { 0x54,&0x65,&0x78,&0x74,&0xE5,0x92,&0x8C,&0xE4,&0xB8,&0xAD,0xE6,&0x96,&0x87&};memset(&str,&0,&14&);memcpy(&str,&a,&13&);CString strGB;/*可逆// int&n&=&(str[0]+256)*256+str[1]+256;// char&c1,c2;// c1&=&n/256&-&256;// c2&=&n%256&-&256;// strGB.Format("%c%c",&c1,&c2&);*/// LPSTR lpstr&=&new&char[1024];LPWSTR lp&=&new&unsigned&short[1024];// for(&int&i=0;&i&3;i++)// lp[i]&=&(str[i*2]+256)*256&+&str[i*2+1]+256;// nLeft =&strTemp.GetAt(0)&+&256;// nRight =&strTemp.GetAt(1)&+&256;// nCode&=&(&nLeft&&8&)&+&nRmemset(&lp,&0,&1024&);// WideCharToMultiByte(&CP_UTF8,&0,&lp,&3,&lpstr,&1024,&NULL,&NULL&);MultiByteToWideChar(&CP_UTF8,&0,&str,&100,&lp,&1024);strGB.Empty();for(&int&i=&0;&i&&100;&i++&){char&c1,c2;c1&=&lp[i]/256-256;c2&=&lp[i]%256-256;//strGB.Format("%c%c",c1,c2);strGB&+=&c1&+&c2;}(发表于 14:01:00)&sandy6173:呵呵,我忘记给出UTF-8&转&GB2312的代码,对不起啊,代码如下:(发表于 9:52:00)&sandy6173:char&*&CXmlProcess::TranslateUTF_8ToGB(char&*xmlStream,&int&len)&&&//len&是xmlStream的长度{&char&*&newCharBuffer&=&new&char[len];&&&&&int&index&=0;&int&nCBIndex&=&0;&&&&&while(index&&&len)&{&&&&&&&&&if(xmlStream[index]&&&0)&&&&&//&如果是GB2312的字符&{newCharBuffer[nCBIndex]&=&xmlStream[index];&&&&//直接复制index&+=&1;&&&&&&&&&&&&&&//源字符串偏移量1nCBIndex&+=&1;&&&&&&&&&&&//目标字符串偏移量1&}&else&&&&&&&&&&&&&&&&&//如果是UTF-8的字符&{WCHAR&*&Wtemp&=&&this-&UTF_8ToUnicode(xmlStream&+&index);&&//先把UTF-8转成Unicodechar&*&Ctemp&&=&this-&UnicodeToGB2312(*Wtemp);//再把Unicode&转成&GB2312&&&&&&&&&&&&newCharBuffer[nCBIndex]&=&*&C&&&&&&&&&//&复制newCharBuffer[nCBIndex&+&1]&=&*(Ctemp&+&1);index&+=&3;&&&&&//源字符串偏移量3nCBIndex&+=&2;&&&//目标字符串偏移量2&&因为一个中文UTF-8占3个字节,GB2312占两个字节&}&}&newCharBuffer[nCBIndex]&=&0;&//结束符&&&&&return&newCharB &&}(发表于 9:53:00)&Mycro:对于编码函数,效率要求非常高;//将2进制数转换成16进制static&char*&BinToHex(char&pc);可以这样写:int&CChineseCodeLib::BinToInt(char&*pBin){int&m_Dec&=&0;&&&&int&m_Len&=&strlen(pBin);for(int&i&=0&;i&&&m_Len&;i&++){&&&&&&&&m_Dec&=&(m_Dec&&&&1)&+&(pBin[i]&-&'0');}return&m_D}(发表于 1:19:00)&Mycro://看了1个多小时,原来是这个意思WCHAR*&CXmlProcess::UTF_8ToUnicode(char&*pText){&&&&char&char_char&char_char&char_char&uchar[2];WCHAR&*char_one&=&pText[0];char_two&=&pText[1]);char_three&=&pText[2];uchar[1]&=&((char_one&&&0x0F)&&&&4)&+&((char_two&&&&2)&&&0x0F);uchar[0]&=&(char_two&&&0x03)&&&&6&+&(char_three&&&0x3F);unicode&=&(WCHAR&*)return&}(发表于 3:28:00)&Mycro://对不起,少加了个扩号WCHAR*&CXmlProcess::UTF_8ToUnicode(char&*pText){char&uchar[2];WCHAR&*char_one&=&pText[0];char_two&=&pText[1]);char_three&=&pText[2];uchar[1]&=&((pText[0]&&&0x0F)&&&&4)&+&((pText[1]&&&&2)&&&0x0F);uchar[0]&=&((pText[1]&&&0x03)&&&&6)&+&(pText[2]&&&0x3F);unicode&=&(WCHAR&*)return&}(发表于 3:40:00)&zztop5384:int&WideCharToMultiByte(UINT&CodePage,&//&code&pageDWORD&dwFlags,&//&performance&and&mapping&flagsLPCWSTR&lpWideCharStr,&//&wide-character&stringint&cchWideChar,&//&number&of&chars&in&stringLPSTR&lpMultiByteStr,&//&buffer&for&new&stringint&cbMultiByte,&//&size&of&bufferLPCSTR&lpDefaultChar,&//&default&for&unmappable&charsLPBOOL&lpUsedDefaultChar&//&set&when&default&char&used);&//将宽字符转换成多个窄字符这些只是函数原型,并没有具体实现(发表于 10:27:00)&zztop5384:帮忙弄以下(发表于 10:35:00)&鬼龙之舞:支持楼主!是因为你我才写出来的,不管是在体积还是在速度,相信都比楼主的强一点,如果不考虑移植性的话感谢楼主!!UTF8toUnicode&proc&uses&esi&edi&lpszBuf_OUT,lpszUTF8_INmov&esi,lpszUTF8_INmov&edi,lpszBuf_OUT.while&TRUE&mov&al,[esi].if&sbyte&ptr&al&&0mov&al,[esi]and&al,bshl&al,4mov&[edi+1],almov&al,[esi+1]and&al,bshr&al,2or&[edi+1],almov&al,[esi+1]and&al,11bshl&al,6mov&[edi+0],almov&al,[esi+2]and&al,bor&&[edi+0],aladd&edi,2add&esi,3.elseif&alxor&ah,ahstoswinc&esi.elsemov&WORD&ptr&[edi],0.break.endif.endwretUTF8toUnicode&endp(发表于 16:11:00)&鬼龙之舞:UnicodetoUTF8&proc&&uses&esi&edi&lpBuf_OUT,lpszUTF8_INmov&esi,lpszUTF8_INmov&edi,lpBuf_OUT.while&TRUE&mov&ax,[esi].if&ax==0stosw.break.elseif&ah==0add&esi,2stosw.elsemov&al,[esi+1]shr&al,4or&&al,bmov&[edi+0],almov&al,[esi+1]and&al,bshl&al,2or&&al,bmov&ah,[esi+0]shr&ah,6or&&al,ahmov&[edi+1],almov&al,[esi+0]and&al,bor&&al,bmov&[edi+2],aladd&edi,3add&esi,2.endif.endwretUnicodetoUTF8&endp(发表于 16:11:00)&鬼龙之舞:晕.格式没有了原文请看http://www.kbadboy.com/viewfull.asp?id=33(发表于 16:13:00)&robin_fox_nan:shines在,提供了一段程序,里面有buffersize&=&WideCharToMultiByte(CP_UTF8,&MB_PRECOMPOSED,&unicode,&wide_size,&NULL,&0,&NULL,&0);&&&&buffer&=&new&char[buffersize+1];但是,我在调试的时候发现:buffersize似乎已经预先留了&\0&的位置,或者是不是我出错了比如:&i&love&you,爱&GB2312是需要14个字节UTF8是需要15个字节,返回时候就是这些了啊,我的地址是:robin-,谁能回答以下,感谢!!(发表于 20:20:00)&kudoo:translateCharToUTF_8的编码不对,请作者检查一下,如:&"你是我的好朋友"转换成了;"浣犳槸鎴戠殑濂芥i脲弸鍚?"正确的应是:"浣犳槸鎴戠殑濂芥湅鍙嬪悧"对于有的编码还能对...交流一下:kudoo.(发表于 19:46:00)&雁过留声:[&原创文档&本文适合中级读者&已阅读34485次&]搞笑,这种害人害己的文章还有这么多人访问。作者光知道&WideCharToMultiByte&可以把&Unicode&转成&GB2312&就不知道也可以把&Unicode&转换为&UTF-8&吗?其实这是一个很简单的程序,都被作者搞复杂了。要实现&GB2312&(其实是GBK)转换为&UTF-8&其实很简单,先用&MultiByteToWideChar&把&GB2312&转换为&Unicode,再用&WideCharToMultiByte&把&Unicode&转换为&UTF-8&就可以了。UTF-8&转换为&GB2312&是个相反的过程,先用&MultiByteToWideChar&把&UTF-8&转换为&Unicode,再用&WideCharToMultiByte&把&Unicode&转换为&GB2312&就可以了。(发表于 9:11:00)&xmwen:/*字符串编码转换&GBK&to&UTF8&(ansi版)*/char&*gbk2utf8(const&char&*strGBK){int&wchar_t&*strUchar&*strUTF8;if&(!strGBK){return&NULL;}len&=&MultiByteToWideChar(CP_GBK,&0,strGBK,&-1,&NULL,0);if&(len&&1){return&NULL;}strUnicode&=&(wchar_t&*)&malloc(sizeof(wchar_t)&*&len);if&(!strUnicode){return&NULL;}len&=&MultiByteToWideChar(CP_GBK,&0,&strGBK,&-1,&strUnicode,&len);if&(len&1){free(strUnicode);return&NULL;}len&=&WideCharToMultiByte(CP_UTF8,&0,&strUnicode,&-1,&NULL,&0,&NULL,&NULL);if&(len&1){free(strUnicode);return&NULL;}strUTF8&=&(char&*)&malloc(sizeof(char)&*&len);if&(!strUTF8){free(strUnicode);return&NULL;}len&=&WideCharToMultiByte&(CP_UTF8,&0,&strUnicode,&-1,&strUTF8,&len,&NULL,NULL);free(strUnicode);if&(len&1){free(strUTF8);return&NULL;}return&strUTF8;}(发表于 19:38:00)}

我要回帖

更多关于 utf 16 gb2312 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信