我试图过滤字符串数组与此断言:NSPredicate搜索LIKE
[NSPredicate predicateWithFormat:@"SELF LIKE[c] '#*!%d'", aNumber]
每串这就好比#WILDCARD ANY_NUMBER是有效的!
但它不工作:( 你能帮我
编辑:?!
NSString *pattern = [@"#*!" stringByAppendingFormat:@"%d", numberVariable];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
NSArray *filteredArray = [anArray filteredArrayUsingPredicate:pred];
数组anArray包含诸如#0字符串-1(numberVariable是-1),但阵列filterdArray是空的,所以正则表达式不起作用
编辑:。
我的解决方案:
“!#ANY_CHARACTERS ANY_NUMBER”NSString *pattern = [@"#.*!\\" stringByAppendingFormat:@"%d", numberVariable];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
NSArray *filteredArray = [anArray filteredArrayUsingPredicate:pred];
您使用'%如果'aNumber'属于'int'类型,那么'd''什么是#*? – CainaSouza
如果你的描述说你想匹配任何数字,那么'aNumber'是什么 – Wain