I have a NSMutableArray consisting of several elements. From this array I want to pick out only those elements that contains the word "example" in any form (words such as exampleId, putexample or getexampleId).
How can this be done?
I have a NSMutableArray consisting of several elements. From this array I want to pick out only those elements that contains the word "example" in any form (words such as exampleId, putexample or getexampleId).
How can this be done?
You can use the filterUsingPredicate:(NSPredicate *)predicate
method:
NSMutableArray *myArray = ...
NSString *nameSearch = ...
[myArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"name CONTAINS %@", nameSearch]];
For more information about NSPredicate
, check out the Predicate Programming Guide.