Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPredicate for evaluating a String

How do I evaluate a string using NSPredicate?

I have used NSPredicateControl and String manipulations to get something like, N92 BEGINSWITH[cd] "n". I want to evaluate this to get a True/False value. How do I get that? Any suggestions ?

like image 213
Suneetha Avatar asked Mar 03 '26 05:03

Suneetha


1 Answers

Try this:-

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");
}
like image 67
Hussain Shabbir Avatar answered Mar 04 '26 21:03

Hussain Shabbir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!