本文介绍了NSCaseInsensitiveSearch在rangeOfCharacterFromSet中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎 NSCaseInsensitiveSearch
在 NSString:rangeOfCharacterFromSet
中不起作用。有人可以解释为什么吗?是正确的行为吗?
It seems that NSCaseInsensitiveSearch
not works in NSString:rangeOfCharacterFromSet
. Can someone explain why? is it correct behaviour?
NSString *string = @"James Bond Always Rocks";
NSRange range = [string rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"J"] options:NSCaseInsensitiveSearch];
NSLog(@"range->%@",NSStringFromRange(range)); //This prints range->{0, 1}
NSString *string = @"James Bond Always Rocks";
NSRange range = [string rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"j"] options:NSCaseInsensitiveSearch];
NSLog(@"range->%@",NSStringFromRange(range)); //This prints range->{2147483647, 0}
推荐答案
从文档中:选项:指定搜索选项的掩码。可以通过将它们与C位或运算符组合来指定以下选项:NSAnchoredSearch,NSBackwardsSearch。所以它似乎是一个正确的行为,不知道为什么只有这两个选项可以应用。
From the documentation: "Options: A mask specifying search options. The following options may be specified by combining them with the C bitwise OR operator: NSAnchoredSearch, NSBackwardsSearch." So it seems like a correct behavior, not sure why only those two options can apply.
这篇关于NSCaseInsensitiveSearch在rangeOfCharacterFromSet中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!