开发者

iPhone: NSComparisonResult and NSDiacriticInsensitiveSearch issue Scandinavian alphabets

I use NSComparisonResult for searching through my array, but when I use NSDiacriticInsensitiveSearch, it cant find immediately Scandinavian alphabets like å æ ø, but it can find such alphabets as á etc. When I remove NSDiacriticInsensitiveSearch in options: , then my search bar can find å æ ø immediately, but ignore à and such.

Is there any solution to this?

EDIT 15 august: I believe using NSScanner (though I have no experience with this) in if logic for detecting å æ ø in searchstring, if they exist, then no nsdiactricinsensitivesearch. If no å æ ø in searchstring, then include nsdiactricinsensitivesearch in nscomparisonresult. I will try to implement this soon and give feedback if this works or not.


My codes:

NSComparisonResult result;
         NSString *setext = searchText;
         NSScanner *scanner = [NSScanner scannerWithString:setext];
         NSString *a = @"å";
         while ([scanner isAtEnd] == NO)
         {
              if ( [scanner scanString:a intoString:NULL])
              {
             [scanner scanUpToString:a intoString: NULL];
             result = [mystr compare:searchText options:(NSCaseInsensitiveSearch) 
                        range:NSMakeRange(0, [searchText length])];              

              }
              else 
              {
              result = [mystr compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) 
                range:NSMakeRange(0, [searchText length])];
        }

    }

But it is a bit slower than my modification of JohnBrighton´s solution:

        NSComparisonResult result;
        NSString *string = searchText;
        NSRange range = [string rangeOfString:@"æ"];
        NSRange range2 = [string rangeOfString:@"ø"];
        NSRange range3 = [string rangeOfString:@"å"];
        if (range.location != NSNotFound || range2.location != NSNotFound || range3.location != NSNotFound ) 

//if ((range.location != NSNotFound)  | (range2.location != NSNotFound ) | (range3.location != NSNotFound ) ) {


{
            result = [mystr compare:searchText options:(NSCaseInsensitiveSearch) 
                         开发者_StackOverflow     range:NSMakeRange(0, [searchText length])];       
        }   
        else {
            result = [mystr compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) 
                              range:NSMakeRange(0, [searchText length])];
        }

Does anyone know whats the difference between || and | in if logic?


Does anyone know whats the difference between || and | in if logic?

You can't use "|" in that case, as it's a bitwise OR operator. "||" is a boolean logical operator, which doesn't work with bits as the bitwise OR.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜