iOS NSStringCompareOptions使用简介

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CX_NO1/article/details/82429648

通常我们对字符串进行compare操作,需要考虑不同的场景,比如:是否区分大小写、特殊字符、比较范围...

NSStringCompareOptions

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

搞定!!!

猜你喜欢

转载自blog.csdn.net/CX_NO1/article/details/82429648