NSPredicate用于评估String

时间:2013-10-28 06:00:00

标签: objective-c macos cocoa nspredicate nspredicateeditor

如何使用NSPredicate评估字符串?

我使用了NSPredicateControl和字符串操作来获得类似N92 BEGINSWITH[cd] "n"的内容。我想评估这个以获得True / False值。我怎么做到的?有什么建议吗?

1 个答案:

答案 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");
}