我想通過比較一個值('stringToCompare')我有一個列表和用戶輸入的搜索文本('searchText')做一個過濾器。代碼片段如下。沒有得到預期NS比較值
NSComparisonResult result = [stringToCompare compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
NSLog(@"Search text: %@", searchText);
NSLog(@"string to compare: %@", stringToCompare);
NSLog(@"result: %i", result);
NSLog(@"NSOrderedsame: %i", NSOrderedSame);
if (result == NSOrderedSame)
{
[self.filteredListContent addObject:genericObj];
}
但是,從下面的NSLog結果可以看出,我似乎無法獲得預期的結果。在這種情況下,我期待結果爲'0',因爲搜索文本'Xot'可以作爲'stringToCompare'的一部分找到。我在這裏錯過了什麼?
2012-01-02 05:13:59.184 onethingaday[5815:707] search text: Xot
2012-01-02 05:13:59.185 onethingaday[5815:707] string to compare: One exotic place you got laid in before. How was it?
2012-01-02 05:13:59.188 onethingaday[5815:707] result: -1
2012-01-02 05:13:59.188 onethingaday[5815:707] NSOrderedsame: 0