swift remove diacritic from Arabic

keloa zoldik

I am trying to remove the Arabic text diacritic. For example I need to convert this َب to this ب , here is my code :

if (text != "") {
    for char in text! {
        print(char)
        print(char.unicodeScalars.first?.value)
        if allowed.contains("\(char)"){
            newText.append(char)
        }
    }
    self.textView.text = text!
} else {
//            TODO :
//            show an alert
    print("uhhh no way")
}

I have tried these solutions but with no luck :

How to remove diacritics from a String in Swift?

NSString : easy way to remove UTF-8 accents from a string?

a.masri

You can use Regex, try this code

 let myString = "الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ"
        let regex = try! NSRegularExpression(pattern: "[\\u064b-\\u064f\\u0650-\\u0652]", options: NSRegularExpression.Options.caseInsensitive)
        let range = NSMakeRange(0, myString.unicodeScalars.count)
        let modString = regex.stringByReplacingMatches(in: myString, options: [], range: range, withTemplate: "")
        print(modString)

Output : الحمد لله رب العالمين

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Remove Arabic Diacritic

Power Query: how to remove diacritic/accent symbols from text

Remove diacritic from only one column in SQL Server

Java remove diacritic

Case and diacritic insensitive matching of regex with metacharacter in Swift

How to remove english text from arabic string in python?

How can I remove arabic words from turkish string with regex?

How to remove Russian and Arabic strings from a text file

Problem with diacritic, getting data from database java

shorten length string ignore Non-Space Characters like arabic diacritic Character without cutting words

Get diacritic insensitive results from Realm database query

How to find and remove first/starting string from an Arabic string having diacritics but maintaining the original diacritics of remaining string

How to remove a certain letter from an arabic text in a dataframe using regular expressions?

Swift remove subviews from superview

Remove suffix from filename in Swift

Remove Item from Struct (Swift)

(swift) remove "\" character from string?

Swift - Remove " character from string

Remove subviews from ScrollView Swift

Remove section from webview in Swift

Swift remove .rawValue from enums

Encoding from Arabic to Western European

Arabic characters from jsp to java

Flutter Image from Arabic URL

Remove non-Arabic words in R

How to remove duplicate row considering the Arabic Phonetics

Python3 : Remove Arabic Punctuation

Remove all English text and leave Arabic text

Regular Expression Remove all English and Arabic numbers?