iOS iOS - 3 months ago 8x
Swift Question

Replace all characters in a String in Swift

Just trying to do a play around with Swift String. I want to replace all the characters in a String to a blank space.

inputString = "This is a String"

outputString = " "

How could I achieve this in swift?


Another way:

let outputString = inputString.stringByReplacingOccurrencesOfString("[^\\s]",
                    withString: " ", 
                       options: .RegularExpressionSearch, 
                         range: Range(inputString.startIndex..<inputString.endIndex))