utf-8: 3位元組乙個字元
unicode: 2位元組乙個字元
gb2312: 1位元組乙個字元
例子:「你」字的utf-8編碼: e4 bd a0 11100100 10111101 10100000
「你」的unicode編碼: 4f 60 01001111 01100000
按照utf-8的編碼規則,分解如下:***x0100 xx111101 xx100000
把除了x之外的數字拼接在一起,就變成「你」的unicode編碼了。
注意utf-8的最前面3個1,表示整個utf-8串是由3個位元組構成的。
經過utf-8編碼之後,再也不會出現敏感字元了,因為最高位始終為1。
類定義class cchinesecode
;類實現
void cchinesecode::utf_8tounicode(wchar_t* pout,char *ptext)
void cchinesecode::unicodetoutf_8(char* pout,wchar_t* ptext)
void cchinesecode::unicodetogb2312(char* pout,wchar_t udata)
void cchinesecode::gb2312tounicode(wchar_t* pout,char *gbbuffer)
void cchinesecode::gb2312toutf_8(string& pout,char *ptext, int plen)
else
}rst[j] = '\0';
//返回結果
pout = rst;
delete rst;
return;
}void cchinesecode::utf_8togb2312(string &pout, char *ptext, int plen)
else
}newbuf[j] = '\0';
pout = newbuf;
delete newbuf;
return;
}
字符集編碼轉換輕鬆實現
在linux上進行編碼轉換時,既可以利用iconv函式族程式設計實現,也可以利用iconv命令來實現,只不過後者是針對檔案的,即將指定檔案從一種編碼轉換為另一種編碼。iconv函式族的標頭檔案是iconv.h,使用前需包含之。include iconv函式族有三個函式,原型如下 1 iconv t ...
字符集之間轉換
字符集之間轉換 特蒐集了utf 8,unicode,gb2312他們3個之間的相互轉換.utf 8 3位元組乙個字元 unicode 2位元組乙個字元 gb2312 1位元組乙個字元 例子 你 字的utf 8編碼 e4 bd a0 11100100 10111101 10100000 你 的unic...
Java String 字符集轉換
1,byte str.getbytes string charsetname 將str按指定的字符集charsetname解碼為字元陣列.返回用指定的字符集charsetname解碼後的字元陣列。2,string byte bytes,string charsetname 構造乙個新的string....