- //找出一个数组
- NSFileManager *fileManager = [NSFileManager defaultManager];
- NSString *defaultPath = [[NSBundle mainBundle] resourcePath];
- NSError *error;
- NSArray *directoryContents = [fileManager contentsOfDirectoryAtPath:defaultPath error:&error]
- //匹配字符串,反回结果, SELF==表示数组中每一个元素
- NSString *match = @"imagexyz-999.png";
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF == %@", match];
- NSArray *results = [directoryContents filteredArrayUsingPredicate:predicate];
- //近似匹配字符串,类似SQL中的语法
- NSString *match = @"imagexyz*.png";
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF like %@", match];
- NSArray *results = [directoryContents filteredArrayUsingPredicate:predicate];
- //不区分大小写匹配
- NSString *match = @"imagexyz*.png";
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF like[cd] %@", match];
- NSArray *results = [directoryContents filteredArrayUsingPredicate:predicate];
- //正则匹配
- NSString *match = @"imagexyz-\\d{3}\\.png";
- NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF matches %@", match];
- NSArray *results = [directoryContents filteredArrayUsingPredicate:predicate];