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

主宰稳场 提交于 2020-07-04 03:06:13

问题


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 || ‘a || ‘U || ‘u in a string to A a U u respectively.

I tried

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

but it doesn't work.


回答1:


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



来源:https://stackoverflow.com/questions/50589284/removing-unicode-u2018-left-single-quotation-mark-like-ali-to-ali-in-swift

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