How can I check if a string (NSString
) contains another smaller string?
I was hoping for something like:
NSString *string = @\"hello bla
Since this seems to be a high-ranking result in Google, I want to add this:
iOS 8 and OS X 10.10 add the containsString: method to NSString
. An updated version of Dave DeLong's example for those systems:
NSString *string = @"hello bla bla";
if ([string containsString:@"bla"]) {
NSLog(@"string contains bla!");
} else {
NSLog(@"string does not contain bla");
}