NSString方法compare详解

传入一个需要比较的字符串。
例如

[value compare:@"********"]
,返回 NSOrderedSame。

options:(NSStringCompareOptions)
传入 NSStringCompareOptions 枚举的值

enum{
    NSCaseInsensitiveSearch = 1,//不区分大小写比较
    NSLiteralSearch = 2,//区分大小写比较
    NSBackwardsSearch = 4,//从字符串末尾开始搜索
    NSAnchoredSearch = 8,//搜索限制范围的字符串
    NSNumbericSearch = 64//按照字符串里的数字为依据,算出顺序。例如 Foo2.txt < Foo7.txt < Foo25.txt
//以下定义高于 mac os 10.5 或者高于 iphone 2.0 可用
    ,
    NSDiacriticInsensitiveSearch = 128,//忽略 "-" 符号的比较
    NSWidthInsensitiveSearch = 256,//忽略字符串的长度,比较出结果
    NSForcedOrderingSearch = 512//忽略不区分大小写比较的选项,并强制返回 NSOrderedAscending 或者 NSOrderedDescending
//以下定义高于 iphone 3.2 可用
    ,
    NSRegularExpressionSearch = 1024//只能应用于 rangeOfString:..., stringByReplacingOccurrencesOfString:...和 replaceOccurrencesOfString:... 方法。使用通用兼容的比较方法,如果设置此项,可以去掉 NSCaseInsensitiveSearch 和 NSAnchoredSearch
}

range:(NSRange)
比较字符串的范围

结构变量:
location: 需要比较的字串起始位置(以0为起始)
length: 需要比较的字串长度

返回值:

typedef enum _NSComparisonResult {
     NSOrderedAscending = -1,    // < 升序
     NSOrderedSame,              // = 等于
     NSOrderedDescending   // > 降序
} NSComparisonResult; 
 
posted @ 2013-08-27 09:41  子福当自强  阅读(491)  评论(0编辑  收藏  举报
悟道