Osama Khan
Osama Khan

Reputation: 57

Search arabic text while ignoring diacritics or accents

Search feature works fine when I use the Arabic with the vowels (fatha, kasra, etc.). How can I search the Arabic text while being vowels/accents insensitive?

For example, if I search for واليوم it should display all results like وَالْيَوْمِ

This is the code I use with vowels (diacritics).

 let arabicMatch = Dua.arabic.rangeOfString(searchText, options: NSStringCompareOptions.CaseInsensitiveSearch)

For swift and iOS 9.

Upvotes: 2

Views: 978

Answers (2)

Marwan Alqadi
Marwan Alqadi

Reputation: 855

or you can make normalize string

extension String {

func normalizeArabic() -> String {
    let newString = NSMutableString(string: self) as CFMutableString
    CFStringTransform(newString, nil, kCFStringTransformLatinArabic, Bool(truncating: 0))
    CFStringTransform(newString, nil, kCFStringTransformStripCombiningMarks, Bool(truncating: 0))
    return newString as String
}}

Upvotes: 0

Wain
Wain

Reputation: 119031

NSStringCompareOptions also has a DiacriticInsensitiveSearch you can use (in the same way as the case insensitive).

Upvotes: 5

Related Questions