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.

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
                                                 range:NSMakeRange(0, [normalizedSearch length])
                                                locale:[NSLocale currentLocale]];
if (result == NSOrderedSame) {
// Output: same

1 comment:

  1. I feel satisfied to read your blog, you have been delivering a useful & unique information to our vision even you have explained the concept as deep clean without having any uncertainty, keep blogging. ios app development online course Bangalore