问题
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