I am currently trying to replace specific characters in a string using Swift 3.
var str = "Hello"
var replace = str.replacingOccurrences(of: "Hello", with: "_____")
print(replace)
This will print: _____ but my problem occurs when str changes and consists of a different number of characters or several words such as:
var str = "Hello World"
Now I want the replace variable to update automatically when str is changed. All characters except 'Space' should be replaced with _ and later print _____ _____ which is supposed to represent Hello World.
How can this be implemented?