I want to wipe an input string. Let's start with this:
func foo(s: String) {
s.replaceSubrange(0..<s.characters.count,
with: String(repeating: "0", count: s.characters.count))
}
Predictably, this results in
cannot use mutating member on immutable value: 's' is a 'let' constant
Fine:
func foo(s: inout String) {
s.replaceSubrange(0..<s.characters.count,
with: String(repeating: "0", count: s.characters.count))
}
But now:
'inout String' is not convertible to 'String'
pointing to .character
-- what?!
Oddly enough, when I do:
func foo(s: inout String) {
let n = s.characters.count
s.replaceSubrange(0..<n,
with: String(repeating: "0", count: n))
}
the call to .characters
is completely fine, but
cannot invoke 'replaceSubrange' with an argument list of type '(CountableRange, with: String)'
Using 0...n-1
doesn't work, either.
How can I replace characters in a parameter string?