Reputation: 194
I'm dealing with a document management page. I used NSPredicate
regular expression while got the searchBar.text
from user inputs. An error occurred (as the image below) while the inputs are brackets in Chinese form but went well in English form. If anyone has come across this matter? Thank you.
Here is my code,crash happen to the last row.
NSString * searchStr = [NSString stringWithFormat:@"fileName like[cd] \'*%@*\'",searchDisplayController.searchBar.text];
NSPredicate *predicate = [NSPredicate predicateWithFormat:searchStr];
self.fileArrayAfterPre = [[NSMutableArray alloc] initWithArray:[fileArr filteredArrayUsingPredicate:predicate]];
Upvotes: 0
Views: 101
Reputation: 1698
LIKE: It is use in wildcard expression.
CONTAIN: According to your question you should use the contain[cd] because it match the file with search text.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"fileName CONTAINS[cd] %@",searchDisplayController.searchBar.text];
self.fileArrayAfterPre = [[NSMutableArray alloc] initWithArray:[fileArr filteredArrayUsingPredicate:predicate]];
Upvotes: 2