views:

19

answers:

1

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?

+2  A: 

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.

Jacob Relkin