【发布时间】:2012-02-14 13:27:25
【问题描述】:
我需要实现一个方法,它比较两个字符串是否相等,将一些土耳其字母视为拉丁字母(例如 ı = i)。这是程序中的瓶颈,因此需要尽可能高效地实施。
我不能使用 NSString compare: withOption:nsdiactricinsensitivesearch,因为它不能正确处理土耳其字母。
这是我的算法的实现:
- (NSComparisonResult) compareTurkishSymbol:(unichar)ch with:(unichar)another
{
//needs to be implemented
//code like: if (ch == 'ı') doesn't work correctly
}
- (NSComparisonResult)compareTurkish:(NSString*)word with:(NSString*)another
{
NSUInteger i;
for (i =0; i < word.length; ++i) {
NSComparisonResult result =[self compareTurkishSymbol:[word characterAtIndex:i] with:[another characterAtIndex:i]];
if (result != NSOrderedSame) {
return result;
}
}
return another.length > word.length ? NSOrderedDescending : NSOrderedSame;
}
问题是我无法正确比较 unichars。它不能正确比较非 ascii 符号。怎么处理?
【问题讨论】:
-
没有。我不能使用
NSDiacriticInsensitiveSearch,因为它不适用于所有土耳其语非拉丁符号。 -
我找到了解决方案。我可以通过符号代码检查它并作为整数进行比较。
标签: objective-c unichar