The following should work:
NSString *sentence = @"The quick brown fox";
NSString *word = @"quack";
if ([sentence rangeOfString:word].location != NSNotFound) {
NSLog(@"Yes it does contain that word");
}
He uses rangeOfString:to return a structure NSRangeindicating the location of the word, if he can not find it NSRange.locationwill be equal NSNotFound.
source
share