0

如果我想在字符串“red is a color in my crayonbox”中找到单词“color”,我该如何构造它?

谢谢,

4

1 回答 1

2
NSString *stringToSearchFor = @"whatever you want";

[NSPredicate predicateWithFormat:@"name CONTAINS[cd] %@", stringToSearchFor];

要搜索红色或法拉利...

NSPredicate *redPred = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] 'red'"];

NSPredicate *ferraiPred = [NSPredicate predicateWithFormat:@"name CONTAINS[cd] 'ferrari'"];

NSPredicate *compoundPredicate = [NSCompoundPredicate orPredicateWithSubPredicates:[NSArray arrayWithObjects:redPred, ferrariPred, nil]];
于 2013-01-12T23:29:43.120 回答