我正在尝试实现对我的应用程序的搜索。如果您在搜索栏中写了一个确切的单词,那没关系,但是例如,如果我想查找“book”并输入“böök”,变音符号应该无关紧要。我正在使用下面的代码,但它没有用,并且在搜索“New York - Björk”时也失败了。我也尝试了不同的 searchEditedText 组合,但代码变得很恶心。我怎样才能做到这一点?
NSString *searchText = [searchBar.text capitalizedString];
NSString *searchEditedText=[searchBar.text capitalizedString];
NSMutableArray *searchArray = [[[NSMutableArray alloc] init] autorelease];
for (NSDictionary *dictionary in listOfItems) {
NSArray *array = [dictionary objectForKey:@"Names"];
[searchArray addObjectsFromArray:array];
}
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"u" withString:@"ü"];
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"c" withString:@"ç"];
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"U" withString:@"Ü"];
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"C" withString:@"Ç"];
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"o" withString:@"ö"];
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"O" withString:@"Ö"];
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"g" withString:@"ğ"];
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"G" withString:@"Ğ"];
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"s" withString:@"ş"];
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"S" withString:@"Ş"];
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"i" withString:@"ı"];
searchEditedText = [searchEditedText stringByReplacingOccurrencesOfString:@"İ" withString:@"I"];
for (NSString *sTemp in searchArray) {
NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch];
NSRange titleResultsRange2 = [sTemp rangeOfString:searchEditedText options:NSCaseInsensitiveSearch];
if (titleResultsRange2.length > 0 || titleResultsRange.length > 0) {
[copyListOfItems addObject:sTemp];
}
}