How to get rid of array brackets while printing

后端 未结 2 1683
长情又很酷
长情又很酷 2021-01-19 16:19

While printing an array how to get rid of brackets from left and right?

var array = [\"1\", \"2\", \"3\", \"4\"]
println(\"\\(array)\") //It prints [1, 2, 3,         


        
2条回答
  •  无人共我
    2021-01-19 16:36

    You could use a for-in loop:

    (This works for Swift 5)

    let array = [1,2,3,4,5]
    var output = ""
    for number in array{
       output += ", \(number)"
    }
    

提交回复
热议问题