IPhone: NSComparisonResult and NSDiacriticInsensitiveSearch issue Scandinavian Alphabets

I use NSComparisonResult to search my array, but when I use NSDiacriticInsensitiveSearch, it cannot immediately find Scandinavian alphabets such as å æ ø, but it can find alphabets such as etc. When I delete NSDiacriticInsensitiveSearch in the options:, then my search bar can immediately find å æ ø, but ignore à, etc.

Is there any solution for this?

EDIT August 15: I believe that using NSScanner (although I have no experience with this), if there is logic to detect å æ ø in the searchstring, if they exist, then there is no nsdiactricinsensitivesearch. If there is no å æ ø in the searchstring, include nsdiactricinsensitivesearch in nscomparisonresult. I will try to implement this in the near future and give feedback if this works or not.


My codes are:

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 this is a bit slower than my modification of John Brighton'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) range:NSMakeRange(0, [searchText length])]; } else { result = [mystr compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; } 

Does anyone know the difference between || and | in case of logic?

+4
source share
1 answer

Does anyone know the difference between || and | in case of logic?

You cannot use "|" in this case, since it is a bitwise OR operator. "||" is a logical logical operator that does not work with bits as a bitwise OR.

+1
source

All Articles