Swift:在索引处替换字符串数组


97

我有以下字符串数组:

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

例如,我如何用另一个字符串替换索引为2(“值3”)的第三个字符串?

Answers:


247

就那么简单:

stringArray[2] = "new string"

12
谢谢。有时,忘记这些小事情很容易,您最终会在Google上搜索“ replace array element”!
Womble

@Womble我想那是让我们忘记这一点的敏捷风格。我敢肯定,没有人会忘记它是如何用C ++完成的
Hasan

我相信,我已经寻找答案多次,一直到达这里😂
Maneesh中号
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.