Skip to content

Searching, Comparing, and Sorting Strings

binism edited this page Mar 16, 2016 · 11 revisions

Searching, Comparing, and Sorting Strings

字符串的搜索、比较、排序

字符串对象提供了多种查找字符或者子串、字符串之间的比较方法。这些方法一直按照Unicode标准来判断两个字符序列是否是等价的。字符串类提供比较方法,这些方法能够妥善处理字符序列的组成,当然,如果效率十分重要的情况下,你也可以选择指定的字面搜索。(The string classes provide comparison methods that handle composed character sequences properly, though you do have the option of specifying a literal search when efficiency is important and you can guarantee some canonical form for composed character sequences.)

(字符串对象)查找和比较的方法

(字符串)查找和比较有很多不同变体。最简单的一种是对整个字符串进行查找和比较。其它变型允许你改变方式来对字符序列的执行比较,并进行搜索或比较字符串中特定范围指定的字符; (Other variants allow you to alter the way comparison of composed character sequences is performed and to specify a specific range of characters within a string to be searched or compared; )在给定的(编码)环境下,也能进行字符串查找和比较。 这里是一些基本的查找和比较方式:

Search methods Comparison
rangeOfString: compare:
rangeOfString:options: compare:options:
rangeOfString:options:range: compare:options:range:
rangeOfString:options:range:locale: compare:options:range:locale:
rangeOfCharacterFromSet:
rangeOfCharacterFromSet:options:
rangeOfCharacterFromSet:options:range:

字符串搜索

使用````rangeOfString:...来在一个给定字符串中查找子串。rangeOfCharacterFromSet:...```方法来从指定字符集中查找单个的字符。

Clone this wiki locally