Suppose I have the String value with special accents :
éáüîāṁṇār̥
Is there a universal/dynamic way to convert/strip these types of characters down to a basic formatting like ?..
eauiamnar
To remove specific set of characters from a String in Swift, take these characters to be removed in a set, and call the removeAll(where:) method on this string str , with the predicate that if the specific characters contain this character in the String.
this should be as simple as let characterFromString = Character(textField. text) . NSString is automatically bridged to Swift's String , and the Character class has an init which accepts a single character String ; see the documentation here.
To remove last character of a String in Swift, call removeLast() method on this string. String. removeLast() method removes the last character from the String.
Use stringByFoldingWithOptions
and pass .DiacriticInsensitiveSearch
let s = "éáüîāṁṇār̥"
let r = s.stringByFoldingWithOptions(.DiacriticInsensitiveSearch, locale: nil)
print(r) // prints eauiamnar
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