How to remove diacritics from a String in Swift?

后端 未结 4 2043
醉话见心
醉话见心 2020-12-01 01:32

How to remove diacritics (or accents) from a String (like say change \"één\" to \"een\") in Swift? Do I have to go back to NSString or can it be do

4条回答
  •  孤城傲影
    2020-12-01 01:47

    Answer update for Swift 5.0.1

    func toNoSmartQuotes() -> String {
        let userInput: String = self
        return userInput.folding(options: .diacriticInsensitive, locale: .current)
    }
    

    and use it someTextField.text.toNoSmartQuotes()

提交回复
热议问题