2012-03-22 14 views
0
enum { 
    NSCaseInsensitiveSearch = 1, 
    NSLiteralSearch = 2, 
    NSBackwardsSearch = 4, 
    NSAnchoredSearch = 8, 
    NSNumericSearch = 64, 
    NSDiacriticInsensitiveSearch = 128, 
    NSWidthInsensitiveSearch = 256, 
    NSForcedOrderingSearch = 512, 
    NSRegularExpressionSearch = 1024 
}; 

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope 
{ 
    [self.filteredListContent removeAllObjects]; 
    for (Notice *notice in allNoticeArray) 
    { 
     if ([scope isEqualToString:@"标题"]) 
     { 
      NSComparisonResult result = [notice.title compare:searchText 
                 options:NSWidthInsensitiveSearch 
                 range:NSMakeRange(0, [searchText length])]; 
      if (result == NSOrderedSame) 
      { 
       [self.filteredListContent addObject:notice]; 
      } 
     } 
    } 
} 

notice.titleはすべて中国語です。漢字の検索にはどの検索オプションと比較オプションを使用しますか?

どのような検索オプションと比較オプションを使用しますか?

ありがとうございます。ご多幸を祈る。

答えて

1

私はあなたのシナリオではNSWidthInsensitiveSearchが良いと思います。 (タイトルだけがキーワードで始まるかどうかを確認する必要があります)

漢字では大文字と小文字の区別はありません。あなたがNSBackwardsSearchや他の人のような余分な要件を持っていない場合は、全角と西洋文字の半値幅フォームの違いを無視することができるので、NSWidthInsensitiveSearchは大丈夫です:

NSWidthInsensitiveSearch

検索無視東アジアの文字セットにあるように、全角と半角の文字の幅の違い。

たとえば、全角のラテン小文字「a」(UnicodeコードポイントU + FF41)は、基本的なラテン小文字「a」(UnicodeコードポイントU + 0061)と同じです。

関連する問題