How can I check if a string (NSString) contains another smaller string?
I was hoping for something like:
NSString *string = @\"hello bla
Use the option NSCaseInsensitiveSearch with rangeOfString:options:
NSString *me = @"toBe" ;
NSString *target = @"abcdetobe" ;
NSRange range = [target rangeOfString: me options: NSCaseInsensitiveSearch];
NSLog(@"found: %@", (range.location != NSNotFound) ? @"Yes" : @"No");
if (range.location != NSNotFound) {
// your code
}
Output result is found:Yes
The options can be "or'ed" together and include:
NSCaseInsensitiveSearch NSLiteralSearch NSBackwardsSearch and more