我的aryContacts包含test_tech,test,abc_tech,testing,hh_techvedika
NSArray *arrSeperated = [[[aryContacts objectAtIndex:i]valueForKey:@"contactName"]componentsSeparatedByString:@“_”];
NSPredicate *predicate =[NSPredicate predicateWithFormat:@"contactName CONTAINS [cd]%@",[arrSeperated objectAtIndex:0]];
NSArray *arrContacts1 = [aryContacts filteredArrayUsingPredicate:predicate];
NSPredicate *predicate1 =[NSPredicate predicateWithFormat:@"contactName CONTAINS [cd]%@",[arrSeperated objectAtIndex:1]];
NSArray *arrContacts2 = [aryContacts filteredArrayUsingPredicate:predicate1];
结果:arrContacts1包含test_tech,test,testing 预期:arrContacts1包含test_tech,test
结果:arrContacts2包含test_tech,abc_tech,hh_techvedika 预期:arrContacts2包含test_tech,abc_tech
答案 0 :(得分:1)
尝试以下代码
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"contactName BEGINSWITH [cd]%@", [[arrTempContacts objectAtIndex:i] valueForKey:@"contactName"]];
NSArray *arrContacts = [arrTempContacts filteredArrayUsingPredicate:predicate];
让我知道它是否有效!!!!
快乐的编码!!!