I know how to find a string in another string, that is easy. But in this case I want to find John Smith within the allProfessors string. So I figured I could just split the string and search for both parts, which works how I want:
NSString *fullName = @"John Smith";
NSArray *parts = [fullName componentsSeparatedByString:@" "];
NSString *allProfessors = @"Smith, John; Clinton, Bill; Johnson, John";
NSRange range = [[allProfessors lowercaseString] rangeOfString:[[parts objectAtIndex:0] lowercaseString]];
NSRange range2 = [[allProfessors lowercaseString] rangeOfString:[[parts objectAtIndex:1] lowercaseString]];
if(range.location != NSNotFound && range2.location != NSNotFound) {
NSLog(@"Found");
} else {
NSLog(@"Not Found");
}
What I want to know is, is this the BEST way to do this or is there a more preferred method to do what I want?
In addition to this, what if my fullName is longer than my allProfessors name, such as:
NSString *fullName = @"Gregory Smith";
NSString *allProfessors = @"Smith, Greg; Clinton, Bill; Johnson, John";
I still want there to be a match for Greg Smith and Gregory Smith.