原文摘自:
如果網頁編碼是utf-8的,可以這麼轉換為字串:
如果網頁是gbk(或者gb2312),用utf8轉換的話,pagesource返回nil。這時需要使用gbk編碼做轉換,但是nsstringencoding不含gbk,怎麼辦?用另乙個方法處理一下:
為什麼可以這麼處理?在nsstring.h(按住command,雙擊nsstringencoding即能檢視),對nsstringencoding的定義中,注釋這麼寫著:
note that in addition to the values explicitly listed below, nsstringencoding supports encodings provided by cfstring.
see cfstringencodingext.h for a list of these encodings.
see cfstring.h for functions which convert between nsstringencoding and cfstringencoding.
ubuntu安裝GBK編碼
1 新增gbk編碼 sudo vim var lib locales supported.d local en us.utf 8 utf 8 zh cn.utf 8 utf 8 zh cn.gbk gbk zh cn.gb2312 gb2312 zh cn.gb18030 gb18030 前2個是預...
iOS NSString正常顯示GBK編碼字元
最近在做乙個網路應用,收到xml是gbk編碼的,我用utf8去編碼,結果返回nil的結果,明顯是編碼方法用錯了,得用gbk的編碼方式。方法如下 view plain copy to clipboard print?unsigned long encode cfstringconvertencodin...
VB中的GBK編碼
option explicit function formatnametomac val as string as string dim i as integer dim str as string str for i 1 to len val if clng h hex asc mid val,i...