Answer by Rodolfo Teixeira for How to remove special characters from string...
without removing spaces between wordsextension String { var removeSpecialCharacters: String { return self.components(separatedBy: CharacterSet.alphanumerics.inverted).filter({ !$0.isEmpty...
View ArticleAnswer by Ben Lin for How to remove special characters from string in Swift 2?
Try this:someString.removeAll(where: {$0.isPunctuation})
View ArticleHow to remove special characters from string in Swift 2?
The answer in How to strip special characters out of string? is not working. Here is what I got and it gives me an error func removeSpecialCharsFromString(str: String) -> String { let chars:...
View ArticleAnswer by Martin R for How to remove special characters from string in Swift 2?
In Swift 1.2, let chars = Set("abcde...") created a set containing all characters from the given string. In Swift 2.0 this has to be done as let chars = Set("abcde...".characters) The reason is that a...
View ArticleAnswer by matt for How to remove special characters from string in Swift 2?
Like this: func removeSpecialCharsFromString(text: String) -> String { let okayChars : Set<Character> = Set("abcdefghijklmnopqrstuvwxyz...
View ArticleAnswer by Maksim Kniazev for How to remove special characters from string in...
SWIFT 4: func removeSpecialCharsFromString(text: String) -> String { let okayChars = Set("abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLKMNOPQRSTUVWXYZ1234567890+-=().!_") return text.filter...
View ArticleAnswer by Bisca for How to remove special characters from string in Swift 2?
I think that a cleaner solution could be this approach: extension String { var alphanumeric: String { return self.components(separatedBy: CharacterSet.alphanumerics.inverted).joined().lowercased() } }
View ArticleAnswer by Leo Dabus for How to remove special characters from string in Swift 2?
If you need to keep only ascii printable characters in a string you can just filter them checking if their unicodeScalar values are ascii: extension Character { var isAscii: Bool { return...
View Article