iOS iOS - 1 year ago 102
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?

Answer Source

Another way:

let outputString = inputString.stringByReplacingOccurrencesOfString("[^\\s]",
                    withString: " ", 
                       options: .RegularExpressionSearch, 
                         range: Range(inputString.startIndex..<inputString.endIndex))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download