打印数组时如何摆脱左右括号?
var array = ["1", "2", "3", "4"]
println("\(array)") //It prints [1, 2, 3, 4]
var arrayWithoutBracketsAndCommas = array. //some code
println("\(arrayWithoutBracketsAndCommas)") //prints 1 2 3 4
答案 0 :(得分:11)
你可以这样做:
this
使用Swift 2,使用Xcode b6,来自xhr
的{{1}}方法:
extension Array {
var minimalDescription: String {
return " ".join(map { "\($0)" })
}
}
["1", "2", "3", "4"].minimalDescription // "1 2 3 4"
你能做的意思:
joinWithSeparator
斯威夫特3:
SequenceType
答案 1 :(得分:0)
(适用于Swift 5)
let array = [1,2,3,4,5]
var output = ""
for number in array{
output += ", \(number)"
}