Repository navigation
Characters and Grapheme Clusters
binism edited this page Apr 16, 2016
·
12 revisions
一个字符串常常被认为是一个包含多个字符的序列,但在使用NSString对象或者一般的Unicode字符串时,最好是处理它们的子串而不是处理单个字符。这样做的原因是,在很多情况下用户看见的一个字符是由字符串中的多个字符表示的。NSString有很多适当处理Unicode字符串的方法。这些方法会使Unicode变得简单,但是,你仍然需要提前注意几条事项。
NSString是概念上的平台相关字节序(platform endianness的 UTF-16,没有必要了解任何关于字符串内部存储结构的信息。这意味着,NSString对象的长度、字符、下标索引以及字符范围,都是按照UTF-16字符单元(uint)来表示的,且NSString中的“字符”形式都以16位平台字节序(platform-endianness)的UTF-16单元(unit)来表示的。这是对字符串对象常见的约定。大多数情况下,客户端不必过于在意。只要你在处理子串,范围索引的精确解释不一定显著。(as long as you are dealing with substrings, the precise interpretation of the range indexes is not necessarily significant. )
绝大多数用于写现实生活中使用的语言的码位都是由单个UTF-16单元表示的。但是,有一些不常见的Unicode码位在UTF-16中是由编码代理对(surrogate pairs(两个UTF-16单元))表示。一个编码代理对(surrogate pairs)是一个包含两个UTF-16单元的序列,这个序列使用了特别保留的unit范围,整体代表一个Unicode码位。
- Introduction
- Strings
- Creating and Converting String Objects
- Formatting String Objects
- String Format Specifiers
- Reading Strings From and Writing Strings To Files and URLs
- Searching, Comparing, and Sorting Strings
- Words, Paragraphs, and Line Breaks
- Characters and Grapheme Clusters
- Character Sets
- Scanners
- String Representations of File Paths
- Drawing Strings
- Document Revision History
- Index