I am having string @"King (+$100)".I want to use NSPredicate开发者_开发技巧 to find if string is having (+$[0-9]*).So how to use NSPrdicate
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
精彩评论