使用 NSPredicate 确定一个字符串是否等于另一个字符串
我有一个使用 [CalCalendarStore eventPredicateWithStartDate]
方法返回的 CalEvents NSArray
。从返回的事件中,我试图仅保留那些事件标题 == @"on call"
(不区分大小写)的事件。
我可以使用以下代码将标题包括 @"on call"
的事件保留在数组中(其中“events”是填充有 CalEvents
):
NSPredicate *onCallPredicate = [NSPredicate predicateWithFormat:@"(SELF.title CONTAINS[c] 'on call')"];
[events filteredArrayUsingPredicate:onCallPredicate];
我尝试使用谓词格式字符串,例如:
@"SELF.title == 'on call'"
但这似乎不起作用。
有没有更简单的方法来做到这一点?
I have an NSArray
of CalEvents returned with the [CalCalendarStore eventPredicateWithStartDate]
method. From the events returned, I am trying to keep only those in which the title of the event == @"on call"
(case-insensitive).
I am able to keep in the array those events whose title includes @"on call"
with the following code (where 'events' is a 'NSArray' populated with CalEvents
):
NSPredicate *onCallPredicate = [NSPredicate predicateWithFormat:@"(SELF.title CONTAINS[c] 'on call')"];
[events filteredArrayUsingPredicate:onCallPredicate];
I've tried using a predicate format string like:
@"SELF.title == 'on call'"
but this doesn't seem to work.
Is there an easier way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
[NSPredicate predicateWithFormat:@"title ==[c] 'on call'"];
(
[c]
使相等比较不区分大小写。)Try
[NSPredicate predicateWithFormat:@"title ==[c] 'on call'"];
(The
[c]
makes the equality comparison case-insensitive.)尝试使用格式
@"self.title like[c] 'on call'"
的谓词。以下示例代码输出 2 个字符串:Try predicate with format
@"self.title like[c] 'on call'"
. The following sample code outputs 2 strings: