Removing Unicode U+2018 LEFT SINGLE QUOTATION MARK like ‘Ali to Ali in swift

前端 未结 1 706
再見小時候
再見小時候 2021-01-25 21:27

How to remove Unicode U+2018 LEFT SINGLE QUOTATION MARK from strings like -

Ghulam ‘Ali, ‘Ali Khel,‘Ali Sher ‘Alaqahdari.

I want to remove occurrences of ‘A ||

相关标签:
1条回答
  • 2021-01-25 21:46

    Since the U+2018 character doesn't appear to be treated as a diacritic, you can simple search for such characters and remove them.

    Here is the Swift 4 version (as specified in your original question) that removes diacritics and these specific quotation marks:

    var myString = "Sozmah Qal‘ah"
    var diacriticRemovedString = myString.folding(options: .diacriticInsensitive, locale: Locale.current).replacingOccurrences(of: "‘", with: "")
    print(diacriticRemovedString)
    

    Output:

    Sozmah Qalah

    0 讨论(0)
提交回复
热议问题