《UTF 8與GB2312之間的互換》的改進

2021-04-20 07:11:45 字數 1168 閱讀 6275

在utf-8,與unicode之間轉換的時候,用二進位制運算,代替了字串的轉換。

utf-8乙個漢字,用3個位元組,而unicode用2個位元組。

對應關係如下:

utf-8編碼: [1,1,1,0,a5,a6,a7,a8], [1,0,b3,b4,b5,b6,b7,b8], [1,0,c3,c4,c5,c6,c7,c8];

對應的unicode編碼:[a5,a6,a7,a8,b3,b4,b5,b6], [b7,b8,c3,c4,c5,c6,c7,c8] 。

因此我們只需進行位操作,即可達到目的;

如: // 把utf-8轉換成unicode

void cchinesecodelib::utf_8tounicode(wchar* pout,char *ptext)

// unicode 轉換成utf-8

void cchinesecodelib::unicodetoutf_8(char* pout,wchar* ptext)

// 把unicode 轉換成 gb2312

void cchinesecodelib::unicodetogb2312(char* pout,unsigned short udata)

// gb2312 轉換成 unicode

void cchinesecodelib::gb2312tounicode(wchar* pout,char *gbbuffer)

//gb2312 轉為 utf-8

void cchinesecodelib::gb2312toutf_8(string& pout,char *ptext, int plen)

else }

rst[j] = ''/0'';

//返回結果

pout = rst;

delete rst;

return;

}//utf-8 轉為 gb2312

void cchinesecodelib::utf_8togb2312(string &pout, char *ptext, int plen)

else }

newbuf[j] = ''/0'';

pout = newbuf;

delete newbuf;.

return;

} **在win2k,vc++60 下編譯,測試通過.

UTF 8與GB2312之間的互換

winapi的兩個函式 widechartomultibyte multibytetowidechar。int multibytetowidechar uint codepage,code page dword dwflags,character type options lpcstr lpmult...

gb2312與UTF 8之間的互相轉換

function chinese2unicode salon dim i dim salon one dim salon unicode for i 1 to len salon salon one mid salon,i,1 salon unicode salon unicode chr 38 s...

在PHP中進行GB2312與UTF 8的互換。

因為證書中有中文,所以需要在php中進行gb2312與utf 8的互換。網上搜尋一下這方面相關資料,說是需要php iconv.dll的支援,可是我在php5資料夾中根本找不到這個檔案,但是奇怪的是在php4中有這個,然後我將php4中的php iconv.dll檔案,複製到system32下,卻提...