3

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 ?

Vinod VT
  • 6,946
  • 11
  • 51
  • 75
Suneetha
  • 67
  • 5

1 Answers1

2

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");
}
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56