Monday, December 17, 2012

iOS - Search or compare korean text

In our UItableView search, we are using the below code to search a typed text in the cell content

 NSComparisonResult result = [eachCellContent compare:searchText options:NSDiacriticInsensitiveSearch|NSCaseInsensitiveSearch range:NSMakeRange(0, [searchText length])];

This is working fine. But this is not working with korean text.

E.g:
suppose one of the cell text is "소".//we are getting this combination by typing these two letters   ㅅ and ㅗ
If we type ㅅ only , our compare method is not working and so not listing the "소". (it is working if we type both ㅅ and ㅗ )

But the above example is working well with AddressBook application.

Is there any other compare method to support this ? (we also need this NSDiacriticInsensitiveSearch|NSCaseInsensitiveSearch )

Updated on 2013-01-14

Got solution from stackoverflow

NSString *normalizedContent = [eachCellContent decomposedStringWithCanonicalMapping];
NSString *normalizedSearch = [searchText decomposedStringWithCanonicalMapping];
and then compare these.


NSString *eachCellContent = @"소";
NSString *searchText = @"ㅅ";

NSString *normalizedContent = [eachCellContent decomposedStringWithCanonicalMapping];
NSString *normalizedSearch = [searchText decomposedStringWithCanonicalMapping];

NSComparisonResult result = [normalizedContent compare:normalizedSearch
                                               options:NSDiacriticInsensitiveSearch|NSCaseInsensitiveSearch
                                                 range:NSMakeRange(0, [normalizedSearch length])
                                                locale:[NSLocale currentLocale]];
if (result == NSOrderedSame) {
    NSLog(@"same");
}
// Output: same
 



No comments:

Post a Comment