I have an array like
NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"How many degrees ", @"Which club degree", @"body building", nil];
A want to filter only those string contains degree. I am using old IOS, i don't have [string stringcontains] method
The required Array must have -> 1. How many degrees 2. Which club degree
First Method I use
NSString *strToMatch=@"degree";
for (NSString *description in arr)
{
NSComparisonResult result = [description compare:strToMatch options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [strToMatch length])];
if (result == NSOrderedSame)
{
// statement to run on comparison succeeded..
}
}
Second Method
for (NSString *description in arr)
{
if ([description rangeOfString:strToMatch options:NSCaseInsensitiveSearch].location != NSNotFound)
{
NSLog(@"I am matched....");
}
}
It is working fine. I have shown you the code to compare a single string but i have to compare this array with another array of string. I want to speed up my code. Is there any other better approach to find it.
And how can we create a NSPredicate to compare two array of string. Find first arrray of string as a substring in second array.
And which approach is fast.
Thanks in Advance.