NSString进行比较的方法和属性
2017-05-12 09:57
190 查看
#pragma mark *** String comparison and equality ***
//这是字符串用来比较的方法
/* In the compare: methods, the range argument specifies the subrange, rather than the whole, of the receiver to use in the comparison. The range is not applied to the search string. For example, [@"AB" compare:@"ABC" options:0 range:NSMakeRange(0,1)]
compares "A" to "ABC", not "A" to "A", and will return NSOrderedAscending.
*/
- (NSComparisonResult)compare:(NSString *)string;
- (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask;
- (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSRange)compareRange;
- (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSRange)compareRange
locale:(nullable id)locale; // locale arg used to be a dictionary pre-Leopard. We now accept NSLocale. Assumes the current locale if non-nil and non-NSLocale.
nil continues to mean canonical compare, which doesn't depend on user's locale choice.
- (NSComparisonResult)caseInsensitiveCompare:(NSString *)string;//忽略大小写进行字符串比较
- (NSComparisonResult)localizedCompare:(NSString *)string;//本地化比较
- (NSComparisonResult)localizedCaseInsensitiveCompare:(NSString *)string;//本地化比较并且不区分大小写
- (NSComparisonResult)localizedStandardCompare:(NSString *)string;//它对应的选项是 NSCaseInsensitiveSearch 、 NSNumericSearch 、NSWidthInsensitiveSearch 以及 NSForcedOrderingSearch 。如果我们要在UI上显示一个文件列表,用它就最合适不过了。
返回值NSComparisonResult是一个结构体类型
typedef NS_ENUM(NSInteger, NSComparisonResult) {NSOrderedAscending = -1L, NSOrderedSame, NSOrderedDescending};
NSOrderedAscending升序,代表左边的值比右边的小;
NSOrderedSame左右两个值大小相同;
NSOrderedDescending降序,代表左边的值比右边的大。
比较方法:根据输入的options值决定比较顺序,依次比较各个字符的值的大小(a-z依次递增),第一个不一样的值决定比较结果大小
参数类型NSStringCompareOptions是一个结构体类型
typedef NS_OPTIONS(NSUInteger, NSStringCompareOptions) {
NSCaseInsensitiveSearch = 1, /* 不区分大小写比较 */
NSLiteralSearch = 2,
/* 区分大小写*/
NSBackwardsSearch = 4,
/* 从字符串尾端搜索*/
NSAnchoredSearch = 8,
/* 搜索限制范围的字符串*/
NSNumericSearch = 64,
/* 以字符串中的数字为标准比较*/
NSDiacriticInsensitiveSearch , /* 忽略“-”号*/
NSWidthInsensitiveSearch ,
/* 忽略字符串长度 */
NSForcedOrderingSearch ,
/* 忽略不区分大小写比较的选项,并强制返回 NSOrderedAscending 或者 NSOrderedDescending*/
NSRegularExpressionSearch NS_ENUM_AVAILABLE(10_7, 3_2) = 1024
/* Applies to rangeOfString:..., stringByReplacingOccurrencesOfString:..., and replaceOccurrencesOfString:... methods only; the search string is treated as an ICU-compatible regular expression; if set, no other options can apply except
NSCaseInsensitiveSearch and NSAnchoredSearch */
};
location: 需要比较的字符串起始位置(以0为起始)
//这是字符串用来比较的方法
/* In the compare: methods, the range argument specifies the subrange, rather than the whole, of the receiver to use in the comparison. The range is not applied to the search string. For example, [@"AB" compare:@"ABC" options:0 range:NSMakeRange(0,1)]
compares "A" to "ABC", not "A" to "A", and will return NSOrderedAscending.
*/
- (NSComparisonResult)compare:(NSString *)string;
- (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask;
- (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSRange)compareRange;
- (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSRange)compareRange
locale:(nullable id)locale; // locale arg used to be a dictionary pre-Leopard. We now accept NSLocale. Assumes the current locale if non-nil and non-NSLocale.
nil continues to mean canonical compare, which doesn't depend on user's locale choice.
- (NSComparisonResult)caseInsensitiveCompare:(NSString *)string;//忽略大小写进行字符串比较
- (NSComparisonResult)localizedCompare:(NSString *)string;//本地化比较
- (NSComparisonResult)localizedCaseInsensitiveCompare:(NSString *)string;//本地化比较并且不区分大小写
- (NSComparisonResult)localizedStandardCompare:(NSString *)string;//它对应的选项是 NSCaseInsensitiveSearch 、 NSNumericSearch 、NSWidthInsensitiveSearch 以及 NSForcedOrderingSearch 。如果我们要在UI上显示一个文件列表,用它就最合适不过了。
返回值NSComparisonResult是一个结构体类型
typedef NS_ENUM(NSInteger, NSComparisonResult) {NSOrderedAscending = -1L, NSOrderedSame, NSOrderedDescending};
NSOrderedAscending升序,代表左边的值比右边的小;
NSOrderedSame左右两个值大小相同;
NSOrderedDescending降序,代表左边的值比右边的大。
比较方法:根据输入的options值决定比较顺序,依次比较各个字符的值的大小(a-z依次递增),第一个不一样的值决定比较结果大小
参数类型NSStringCompareOptions是一个结构体类型
typedef NS_OPTIONS(NSUInteger, NSStringCompareOptions) {
NSCaseInsensitiveSearch = 1, /* 不区分大小写比较 */
NSLiteralSearch = 2,
/* 区分大小写*/
NSBackwardsSearch = 4,
/* 从字符串尾端搜索*/
NSAnchoredSearch = 8,
/* 搜索限制范围的字符串*/
NSNumericSearch = 64,
/* 以字符串中的数字为标准比较*/
NSDiacriticInsensitiveSearch , /* 忽略“-”号*/
NSWidthInsensitiveSearch ,
/* 忽略字符串长度 */
NSForcedOrderingSearch ,
/* 忽略不区分大小写比较的选项,并强制返回 NSOrderedAscending 或者 NSOrderedDescending*/
NSRegularExpressionSearch NS_ENUM_AVAILABLE(10_7, 3_2) = 1024
/* Applies to rangeOfString:..., stringByReplacingOccurrencesOfString:..., and replaceOccurrencesOfString:... methods only; the search string is treated as an ICU-compatible regular expression; if set, no other options can apply except
NSCaseInsensitiveSearch and NSAnchoredSearch */
};
location: 需要比较的字符串起始位置(以0为起始)
相关文章推荐
- Collections.sort方法(可以根据集合中类的属性的比较对集合内的类进行排序)
- 使用.net-Synchronized属性进行静态方法的同步
- 对对象类型和调用方法属性进行存储以提升反射性能
- 比较有用的常用dom对面属性&方法
- 使用setter方法和=号进行属性赋值的区别
- 使用setter方法和=号进行属性赋值的区别
- 使用方法参数与对象属性之间的比较
- 【日记】利用VB.NET实现MYSQL和MSSQL进行批量插入记录的方法及比较
- C++和Java的属性访问和方法调用 效率比较
- 利用反射对私有属性/方法进行设置/调用
- Android JNI开发高级篇有关Android JNI开发中比较强大和有用的功能就是从JNI层创建、构造Java的类或执行Java层的方法获取属性等操作。 一、类的相关操作 1. jclass FindClass(JNIEnv *env, const char *name);
- 对对象类型和调用方法属性进行存储以提升反射性能
- 通过互联网进行产品比较选购的方法
- 通过互联网进行产品比较选购的方法
- 开发中“错误: 意外地调用了方法或属性访问。” 和 第一行错误 的IE 两个问题( JQ 进行转义字符 , 分页JS 调用 时参数问题。)
- 对对象类型和调用方法属性进行存储以提升反射性能
- 通过互联网进行产品比较选购的方法
- 对XML里的属性或元素进行模糊搜索的方法
- Request的RawUrl属性,和其它获取url信息的各种方法比较
- IOS之NSString比较方法