IOS encoding: How to Create GBK Encoding

Source: Internet
Author: User

From http://www.cnblogs.com/kiao295338444/articles/2590031.html

 

 

We know that the web page is downloaded using the nsurlconnection proxy method and saved to an nsdata file,

 

 

 
Nsmutabledata * pagedata;
[Pagedata appenddata: Data];

 

If the webpage code is UTF-8, it can be converted to a string like this:

 

 
Nsstring * pagesource = [[nsstring alloc] initwithdata: pagedata encoding: nsutf8stringencoding];

 

If the webpage is GBK (or gb2312) and utf8 is used for conversion, pagesource returns nil. In this case, GBK encoding is required for conversion, but nsstringencoding does not include GBK. What should I do? Use another method:

 

 
Nsstringencoding gbkencoding = encode (kcfstringencodinggb_18030_2000); nsstring * pagesource = [[nsstring alloc] initwithdata: pagedata encoding: gbkencoding];
Why? In nsstring. H (hold down the command and double-click nsstringencoding to view it), in the definition of nsstringencoding, the comment says:
 
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. 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.