I am having string @"King (+$100)".I want to use NSPredicate to find if string is having (+$[0-9]*).So how to use NSPrdicate
+2
A:
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
Yannick L.
2010-02-15 11:21:41
Thanks.I got it.One more thing is that how get to that particular string.if the pattern matches i.e [predicate evaluateWithObject:string]; if this fuction retuns true is there way to get using NSPredicate (+$100).
shilpa
2010-02-15 12:14:22
I don't know how to do that with the standard API. I have searched, but nothing...So I guess that you'll have to work with the NSString and/or the NSScanner to find your occurrence.
Yannick L.
2010-02-15 13:58:01