0

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.

1
  • 2
    Surely you tried something, didn't you? Don't hesitate to show your attempt! Commented Jun 14, 2017 at 18:58

1 Answer 1

3

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"]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.