zoukankan      html  css  js  c++  java
  • iOS中NSArray的过滤 HA

    1. //找出一个数组   
    2.    NSFileManager *fileManager = [NSFileManager defaultManager];  
    3.     NSString *defaultPath = [[NSBundle mainBundle] resourcePath];  
    4.     NSError *error;  
    5.       
    6.     NSArray *directoryContents = [fileManager contentsOfDirectoryAtPath:defaultPath error:&error]  
    7. //匹配字符串,反回结果, SELF==表示数组中每一个元素  
    8. NSString *match = @"imagexyz-999.png";  
    9.     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF == %@", match];  
    10.     NSArray *results = [directoryContents filteredArrayUsingPredicate:predicate];  
    11.   
    12. //近似匹配字符串,类似SQL中的语法  
    13. NSString *match = @"imagexyz*.png";  
    14.     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF like %@", match];  
    15.     NSArray *results = [directoryContents filteredArrayUsingPredicate:predicate];  
    16. //不区分大小写匹配  
    17. NSString *match = @"imagexyz*.png";  
    18.     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF like[cd] %@", match];  
    19.     NSArray *results = [directoryContents filteredArrayUsingPredicate:predicate];  
    20. //正则匹配  
    21. NSString *match = @"imagexyz-\\d{3}\\.png";  
    22.     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF matches %@", match];  
    23.     NSArray *results = [directoryContents filteredArrayUsingPredicate:predicate];
  • 相关阅读:
    Python基础-博客
    已开发程序查询
    新语法
    html基础
    python操作excel
    Selenium
    练习2---(request,ajax爬取头条数据)
    练习1---request+正则(猫眼电影)
    框架---scrapy(基本用法)
    框架---Scrapy (框架安装)
  • 原文地址:https://www.cnblogs.com/halou/p/2061071.html
Copyright © 2011-2022 走看看