问题
I have recently developed a book for iphone and implemented search function in this app. but after testing the app on a real iphone I wondered it cant find all of the search Terms. (using farsi keyboard on my mac)
for example it cant find words containing "ی" character because the search terms contains "ي" character which is inserted from iphone arabic keyboard!!
my texts are a lot and I cant find all of theses similar characters!!
Is there any way to convert my farsi text to arabic text?
回答1:
You probably need to normalize the text or use a search routine that is insensitive to the various Arabic letter forms (initial, medial, final, isolated), or insensitive to diacritics.
In particular 'ي' is U+064A 'ARABIC LETTER YEH' while 'ی' is U+FBFC 'ARABIC LETTER FARSI YEH ISOLATED FORM'.
You might look at the method localizedCaseInsensitiveCompare:
or the various search options such as to NSDiacriticInsensitiveSearch
.
Here's a blog post discussing the issue, though it doesn't actually say how to solve the problem: http://www.siao2.com/2006/02/14/531572.aspx
回答2:
I fix the issue with this method:
- (NSString *)correctSearchTermCharcters:(NSString *)searchTerm
{
return [searchTerm stringByReplacingOccurrencesOfString:@"ي" withString:@"ی"];
}
if you need you can replace more characters.
来源:https://stackoverflow.com/questions/11261258/cant-search-in-farsi-text-with-arabic-keyboard-on-iphone