ios--character encoding, conversion between NSString and UTF-8

Source: Internet
Author: User
Tags control characters

ASCII code believe very familiar with, but they have been unable to remember the Basic Law, sometimes used up very uncomfortable.

ASCII, a total of 7 digits, representing 128 characters, typically preceded by a 0 complement of 8 bits to form a bit. 0~31 and 127 are control characters, cannot be printed, 32 is a space, and (hex:0x30) is 0;65 (hex:0x41) is a;97 (hex:0x61) is a.


Gb2312:ansi encoding, a ASNI encoding the most initial ASCII code expansion, in order to meet the domestic use of Chinese characters in the computer needs, the Chinese National Standards Administration issued a series of men's character set national standard Code, collectively known as GB Code, or GB code. One of the most influential is the "basic set of Chinese character encoding characters for Information interchange", which was issued in 1980, the standard number is GB 2312-1980, because its use is very common, also commonly known as GB code. GB2312 is a simplified Chinese character set, consisting of 6,763 commonly used Chinese characters and 682 of full-width non-Chinese characters. GB2312 encoding represents a Chinese character in two bytes, so it is theoretically possible to represent 256x256=65536 characters. (Excerpt from Baidu Encyclopedia)


GBK: Chinese character inner code expands the standard, K is the expansion in Hanyu Pinyin "expands" the word initials. GBK compatible with GB2312, a total of 21,003 Chinese characters, 883 symbols, and provide 1894 character-word code. (Excerpt from Baidu Encyclopedia)


Unicode: Incorporating all the symbols in the world, including English, Japanese, Chinese, and so on, can now accommodate 100多万个 symbols. This is not efficient, so UTF-8 appears, it can be based on different symbols automatically choose the length of the code.


UTF-8 encoding of Strings in iOS: UTF-8 format for output str strings

[Str stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];


Decoding: Decoding of STR strings with UTF-8 rules

[Str stringbyreplacingpercentescapesusingencoding:nsutf8stringencoding];

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.