can't search in farsi text with arabic keyboard on iphone

心已入冬 提交于 2019-12-10 23:07:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!