This is my current search code.
-(void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope {
[filteredList removeAllObjects];
for(Location *item in list)
{
NSRange result = [item.title rangeOfString:searchText options:NSCaseInsensitiveSearch range:NSMakeRange(0, [searchText length])];
if(result.location != NSNotFound)
{
[filteredList addObject:item];
}
}
}
How would I change this to match any part of the title and not just the start.
Example:
At the moment if I search for ‘Las’, ‘Las Vegas’ will appear in the list, but when I search for ‘Vegas’ it does not.
I want the search term ‘Vegas’ to come back with ‘Las Vegas’
Thanks,
Ashley
Use rangeOfString:options: instead of rangeOfString:options:range:. It is the
rangeparameter that restricts the search to the beginning of the string.Or if for some reason you want to use rangeOfString:options:range: then use this as range:
NSMakeRange(0, [item.title length])