#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//查找名字里面包含“王”的姓
NSArray *array = [[NSArray alloc]initWithObjects:@"小王",@"王力",@"李丽",@"方方", nil];
NSString *match = @"*王*";
//查找姓王的名字,王字必须为首字则修改NSString *[email protected]"王*";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF like %@", match];
NSArray *results = [array filteredArrayUsingPredicate:predicate];
for (id str in results) {
NSLog(@"%@",str);
}
}
return 0;
}
时间: 2024-10-25 12:01:56