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 done within Swift?
You can operate directly on a Swift String
(if "Foundation" is imported):
let foo = "één" let bar = foo.stringByFoldingWithOptions(.DiacriticInsensitiveSearch, locale: NSLocale.currentLocale()) print(bar) // een
Swift 3:
let foo = "één" let bar = foo.folding(options: .diacriticInsensitive, locale: .current) print(bar) // een
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With