如何从Swift中的String数组中提取String

时间:2021-03-31 07:11:40

I have a string array: ["1a", "1b", "1c", "1d"]

我有一个字符串数组:[“1a”,“1b”,“1c”,“1d”]

I want to extract only one of the strings ("1a") so that I can append it to a different string.

我想只提取其中一个字符串(“1a”),以便我可以将它附加到不同的字符串。

How can I do this?

我怎样才能做到这一点?

Thanks!

1 个解决方案

#1


You can get the value of the array via the index
In this case:

您可以通过索引获取数组的值在这种情况下:

myArray[0]

So,

let inital_str = "some string"
let array_element = myArray[0]

And just sum them:

然后总结一下:

let final_string = inital_str + array_element

#1


You can get the value of the array via the index
In this case:

您可以通过索引获取数组的值在这种情况下:

myArray[0]

So,

let inital_str = "some string"
let array_element = myArray[0]

And just sum them:

然后总结一下:

let final_string = inital_str + array_element