I know I can check if a string contains another string like this
NSString *string = @"hello bla bla";
if ([string rangeOfString:@"bla"].location == NSNotFound) {
NSLog(@"string does not contain bla");
} else {
NSLog(@"string contains bla!");
}
But what if I have an NSArray *arary = @[@"one",@"two", @"three", @"four"]
and I wanted to check if a string contains either one of these without just loop or have a bunch of or's (||
). So it would be something like this
if (array contains one or two or three or four) {
//do something
}
But if I have a longer array this becomes tedious so is there another way, without just looping through?
EDIT
I want to check if myArray has any of theses values in valuesArray
valuesArray =@[@"one",@"two", @"three", @"four"];
myArray = [@"I have one head", @"I have two feet", @"I have five fingers"]
OUTPUT
outputArray = @[@"I have one head", @"I have two feet"]
There you go:
arrRet
contains exactly the two desired strings.A little bit more magic later you have your code without writing a loop :P