使用NSPredicate确定一个字符串是否等于另一个字符串 [英] Using NSPredicate to determine if a string equals another string
问题描述
我用[CalCalendarStore eventPredicateWithStartDate]
方法返回了CalEvents的NSArray
.从返回的事件中,我试图仅保留那些事件标题== @"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).
我能够使用以下代码将标题为包括 @"on call"
的那些事件保留在数组中(其中"events"是填充有CalEvents
的"NSArray"):
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'"
,但这似乎不起作用.
@"SELF.title == 'on call'"
but this doesn't seem to work.
有更简单的方法吗?
推荐答案
尝试[NSPredicate predicateWithFormat:@"title ==[c] 'on call'"];
([c]
使相等比较不区分大小写.)
(The [c]
makes the equality comparison case-insensitive.)
这篇关于使用NSPredicate确定一个字符串是否等于另一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!