133

I have the following String Array:

var stringArray:[String] = ["value1", "value2", "value3", "value4"]

how can I replace for example the third String with index 2 ("value 3") with another string?

0

1 Answer 1

331

Simple as that:

stringArray[2] = "new string"
Sign up to request clarification or add additional context in comments.

10 Comments

Thank you. Sometimes, it's easy to forget the little things, and you end up googling for "replace array element"!
I am sure that I have searched for the answer multiple times and always reach here 😂
Another visit to the same page!
@ManeeshM You should go on vacation
Just make sure to check that stringArray.count is less than the index you're attempting to replace the element at!
|

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.