开发者

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜