NSCaseInsensitiveSearch does not work in the rangeOfCharacterFromSet

It NSCaseInsensitiveSearchdoesn't seem to work in NSString:rangeOfCharacterFromSet. Can someone explain why? is this the right behavior?

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
source share
1 answer

From the documentation: "Parameters: mask that defines the search parameters. The following parameters can be set by combining them with the bitwise OR operator: NSAnchoredSearch, NSBackwardsSearch." So this seems like the right behavior, I don't know why only these two options can be applied.

+3
source

Source: https://habr.com/ru/post/1531719/


All Articles