NSCaseInsensitiveSearch not works in rangeOfCharac

2019-08-01 05:13发布

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}

1条回答
我命由我不由天
2楼-- · 2019-08-01 05:43

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.

查看更多
登录 后发表回答