传入一个需要比较的字符串。
例如
- <span style="color:rgb(0,34,0)">[</span>value compare<span style="color:rgb(0,34,0)">:</span><span style="color:rgb(191,29,26)">@</span><span style="color:rgb(191,29,26)">"********"</span><span style="color:rgb(0,34,0)">]</span>
- ,返回 NSOrderedSame。
options:(NSStringCompareOptions)
传入 NSStringCompareOptions 枚举的值
- <span style="color:rgb(166,19,144)">enum</span><span style="color:rgb(0,34,0)">{</span>
- NSCaseInsensitiveSearch <span style="color:rgb(0,34,0)">=</span> <span style="color:rgb(36,0,217)">1</span>,<span style="color:rgb(17,116,10)"><em>//不区分大小写比较</em></span>
- NSLiteralSearch <span style="color:rgb(0,34,0)">=</span> <span style="color:rgb(36,0,217)">2</span>,<span style="color:rgb(17,116,10)"><em>//区分大小写比较</em></span>
- NSBackwardsSearch <span style="color:rgb(0,34,0)">=</span> <span style="color:rgb(36,0,217)">4</span>,<span style="color:rgb(17,116,10)"><em>//从字符串末尾开始搜索</em></span>
- NSAnchoredSearch <span style="color:rgb(0,34,0)">=</span> <span style="color:rgb(36,0,217)">8</span>,<span style="color:rgb(17,116,10)"><em>//搜索限制范围的字符串</em></span>
- NSNumbericSearch <span style="color:rgb(0,34,0)">=</span> <span style="color:rgb(36,0,217)">64</span><span style="color:rgb(17,116,10)"><em>//按照字符串里的数字为依据,算出顺序。例如 Foo2.txt < Foo7.txt < Foo25.txt</em></span>
- <span style="color:rgb(17,116,10)"><em>//以下定义高于 mac os 10.5 或者高于 iphone 2.0 可用</em></span>
- ,
- NSDiacriticInsensitiveSearch <span style="color:rgb(0,34,0)">=</span> <span style="color:rgb(36,0,217)">128</span>,<span style="color:rgb(17,116,10)"><em>//忽略 "-" 符号的比较</em></span>
- NSWidthInsensitiveSearch <span style="color:rgb(0,34,0)">=</span> <span style="color:rgb(36,0,217)">256</span>,<span style="color:rgb(17,116,10)"><em>//忽略字符串的长度,比较出结果</em></span>
- NSForcedOrderingSearch <span style="color:rgb(0,34,0)">=</span> <span style="color:rgb(36,0,217)">512</span><span style="color:rgb(17,116,10)"><em>//忽略不区分大小写比较的选项,并强制返回 NSOrderedAscending 或者 NSOrderedDescending</em></span>
- <span style="color:rgb(17,116,10)"><em>//以下定义高于 iphone 3.2 可用</em></span>
- ,
- NSRegularExpressionSearch <span style="color:rgb(0,34,0)">=</span> <span style="color:rgb(36,0,217)">1024</span><span style="color:rgb(17,116,10)"><em>//只能应用于 rangeOfString:..., stringByReplacingOccurrencesOfString:...和 replaceOccurrencesOfString:... 方法。使用通用兼容的比较方法,如果设置此项,可以去掉 NSCaseInsensitiveSearch 和 NSAnchoredSearch</em></span>
- <span style="color:rgb(0,34,0)">}</span>
range:(NSRange)
比较字符串的范围
结构变量:
location: 需要比较的字串起始位置(以0为起始)
length: 需要比较的字串长度
返回值:
- <span style="color:rgb(166,19,144)">typedef</span> <span style="color:rgb(166,19,144)">enum</span> _NSComparisonResult <span style="color:rgb(0,34,0)">{</span>
- NSOrderedAscending <span style="color:rgb(0,34,0)">=</span> <span style="color:rgb(0,34,0)">-</span><span style="color:rgb(36,0,217)">1</span>, <span style="color:rgb(17,116,10)"><em>// < 升序</em></span>
- NSOrderedSame, <span style="color:rgb(17,116,10)"><em>// = 等于</em></span>
- NSOrderedDescending <span style="color:rgb(17,116,10)"><em>// > 降序</em></span>
- <span style="color:rgb(0,34,0)">}</span> NSComparisonResult;