關於字元的編碼和轉碼

2021-07-15 14:50:47 字數 401 閱讀 8828

在實際開發中,會經常遇到字元編碼的轉換,這裡介紹一種url和string相互轉換的方法

try  catch (unsupportedencodingexception e)
列印結果:

data1--->>>>%e5%8c%97%e4%ba%ac,data2---->>>北京市

這樣就很清楚的知道了,urlencoder.encode是編碼,而urldecoder是解碼

urlencode方法是把任何我們給出的引數轉換成適合放在url中的字串。具體規則:

1。字母,數字,連字元不變。

2。空格轉換成加號。

3。其他所有的字元轉換成用百分號表示,後跟字元的兩位十六進製制編碼。

urldecode功能相反。

python字元編碼與轉碼

詳細文章 需知 1.在python2預設編碼是ascii,python3裡預設是unicode 2.unicode 分為 utf 32 佔4個位元組 utf 16 佔兩個位元組 utf 8 佔1 4個位元組 so utf 16就是現在最常用的unicode版本,不過在檔案裡存的還是utf 8,因為u...

python(字元編碼與轉碼)

一 字元編碼演變史 二 轉碼 1 python2.x 轉碼和解碼 獲取預設編碼格式 msg 我愛北京天安門 msg gb2312 msg.decode utf 8 encode gb2312 gb2312 to gbk msg gb2312.decode gbk encode gbk print m...

PHP檢測當前字元編碼並轉碼

一 檢測當前字串編碼並將編碼改為utf 8 1 獲取當前字串的編碼 encode mb detect encoding str,array ascii utf 8 gb2312 gbk big5 2 將字元編碼改為utf 8 str encode mb convert encoding str,ut...