2010-04-23 141 views

回答

2

NSPredicate在评估时返回true或false,因此您无法创建返回以“a”开头的所有单词的谓词。

您可以创建返回从“a”字真正的谓语,那么句子分割世界,并与谓语类似过滤好话:

NSArray *words = [sentence componentsJoinedByString:@" "]; 
NSPredicate *beginsWithA = [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'a'"]; 
NSArray *wordsBeginsWithA = [words filteredArrayUsingPredicate:beginsWithA]; 
相关问题