I'm viewing an Arabic with diacritics (tashkel) text in a UIWebView. I also have a Search View.
I want to give the UIWebView a keyword and UIWebView finds and highlights it, but the search should ignore the diacritics.
The main text should remain with the diacritics.
example : if the text is " الَلَهُم صَلِ عَلى مُحَمّد و آل مُحمد " and I tell the UIWebView to search for " محمد " it should highlight "مُحَمّد " and " مُحمد " regardless of all the diacritics.
I think of two approaches : 1- I do the find and highlight by Javascript after the UIWebView load. 2- I edit the text by Objective-C before loading the UIWebView.
You have to first strip all the diacritics from the string, then you can compare without any diacritics. Use regular expression to remove the characters you don't want. Check out this fiddle i did, inside the strip()
function you need to add all the diacritics you need to take out.
hope this helps.
The version below does not remove sukoon.
I have converted the eight diacritics (fatha, kasrah, damma, shaddah, sukoon and tanween) into their Unicode equivalent. It is much easier to manipulate Arabic converted into Latin characters in any text editor :
<html>
<head><meta charset="UTF-8"></head>
<body>
<script>document.write("حَرْفٌ".replace(/(\u0652)|(\u0650)|(\u064C)|(\u064E)|(\u064B)|(\u064F)|(\u064D)|(\u0651)/g,""));</script>
</body>
</html>
Resources used:
Arabic Keyboard with diacritics
Unicode Code Converter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With