gpt4 book ai didi

ios - 将具有 "\n"的数组元素合并到 Swift 中的字符串中

转载 作者:搜寻专家 更新时间:2023-10-31 22:01:10 26 4
gpt4 key购买 nike

我正在尝试将字符串数组与 \n 合并,但没有得到任何解决方案。我有以下类型的数组,其中包含部分名称。

let arrSectionName = [
"Section 1",
"Section 2",
"Section 3",
"Section 4",
"Section 5",
"Section 6",
]

现在,我想要上面数组中的这个字符串:

"Section 1 \nSection 2 \nSection 3 \nSection 4 \nSection 5 \nSection 6"

所以最终消息应该显示如下:

警报消息输出:

    Following section which are still pending to complete, please verify and try again:
Section 1
Section 2
Section 3
Section 4
Section 5
Section 6

Section name 是动态的,会在运行时更改并存储在 arrSectionName 中。

最佳答案

你应该使用 joined(separator:) .它连接数组元素并在元素之间添加给定的分隔符字符串。

let str = arrSectionName.joined(separator: " \n")

关于ios - 将具有 "\n"的数组元素合并到 Swift 中的字符串中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51258267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com