shilpa
shilpa

Reputation: 11

NSPredicate usage

I am having string @"King (+$100)".I want to use NSPredicate to find if string is having (+$[0-9]*).So how to use NSPrdicate

Upvotes: 1

Views: 1064

Answers (1)

Yannick Loriot
Yannick Loriot

Reputation: 7136

Try this:

// The string to evaluate
NSString *string = @"King (+$100)";

// The regular expression
NSString *regExp =  @".*\\(\\+\\$[0-9]*\\).*";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regExp];

// Test if the object checks the regular expression 
BOOL ok = [predicate evaluateWithObject:string];

For all documentation on the NSPredicate see: NSPredicate Programming Guide

Upvotes: 3

Related Questions