我有字符串@“King(+ $ 100)”。我想使用NSPredicate来查找字符串是否有(+ $ [0-9] *)。那么如何使用NSPrdicate
答案 0 :(得分:3)
试试这个:
// 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];
有关NSPredicate的所有文档,请参阅: NSPredicate Programming Guide