3
いくつかのトルコ語の文字をラテン語(例えば、ı= i)とみなして、2つの文字列を同等かどうか比較するメソッドを実装する必要があります。プログラムのボトルネックなので、できるだけ効率的に実装する必要があります。目的関数のunichar比較
トルコ語の文字で正しく機能しないため、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以外の記号は正しく比較しません。それに対処する方法?
が見える:それはdoesnのためhttp://stackoverflow.com/questions/7656938/iphone-comparing-strings-with-a-german-umlaut – lqez
いいえ、私は、 'NSDiacriticInsensitiveSearch'を使用することはできませんすべてのトルコ語の非ラテン記号のために働きません。 –
私は解決策を見つけました。私はシンボルコードでそれをチェックし、intとして比較することができます。 –