使用NSPredicate来确定一个string是否等于另一个string
我有[CalCalendarStore eventPredicateWithStartDate]
方法返回的CalEvents的NSArray
。 从返回的事件中,我试图只保留事件标题== @"on call"
(不区分大小写)。
我可以使用下面的代码(其中“events”是一个用CalEvents
填充的“NSArray”)保存标题包含 @"on call"
的事件:
- 详细披露之后的注解细节被按下了吗
- 我应该在ARC的init方法中引用self.property吗?
- 如何设置一个UIPickerView的默认值
- 了解NSRunLoop
- Facebook SDKlogin从不在iOS 9上回拨我的应用程序
NSPredicate *onCallPredicate = [NSPredicate predicateWithFormat:@"(SELF.title CONTAINS[c] 'on call')"]; [events filteredArrayUsingPredicate:onCallPredicate];
我已经尝试使用谓词格式string,如:
@"SELF.title == 'on call'"
但这似乎不工作。
有没有更简单的方法来做到这一点?
2 Solutions collect form web for “使用NSPredicate来确定一个string是否等于另一个string”
尝试[NSPredicate predicateWithFormat:@"title ==[c] 'on call'"];
( [c]
使平等比较不区分大小写。)
尝试使用format @"self.title like[c] 'on call'"
谓词。 以下示例代码输出2个string:
NSArray* ar = [NSArray arrayWithObjects:@"on call", @"I'm on call", @"lala", @"On call", nil]; NSArray* filt = [ar filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self like[c] 'on call'"]]; NSLog([filt description]); //Output "on call", "On call"