如何使用NSPredicate
评估字符串?
我使用了NSPredicateControl
和字符串操作来获得类似N92 BEGINSWITH[cd] "n"
的内容。我想评估这个以获得True / False值。我怎么做到的?有什么建议吗?
答案 0 :(得分:2)
试试这个: -
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[cd]%@", @"n"];
NSString *yourValue=@"nndfj";
BOOL result = [predicate evaluateWithObject:yourValue];
if (result ==YES)
{
NSLog(@"Word begin with n");
}
else{
NSLog(@"Word does not begin with n");
}