Reputation: 21
My String Array contains multiples strings:
var array = ["Test", "Another Test", "Third test"]
I wonder how I can replace all the "e" characters in the array with "*". It´s important for me to always use my array and not create a new one.
Any help would be appriciated.
Upvotes: 0
Views: 3216
Reputation: 38833
You can either do something like this:
var array = ["Test", "Another Test", "Third test"]
for (index, str) in array.enumerated() {
array[index] = str.replacingOccurrences(of: "e", with: "*")
}
Or a simpler solution with map
:
array = array.map({ $0.replacingOccurrences(of: "e", with: "*") })
Both will give you:
["T*st", "Anoth*r T*st", "Third t*st"]
Upvotes: 3