将Ints数组转换为逗号分隔的字符串[duplicate]

时间:2022-04-20 00:16:53

This question already has an answer here:

这个问题在这里已有答案:

I know that if I want to convert an array of Ints to a String, I do this:

我知道如果我想将Ints数组转换为String,我会这样做:

[0,1,1,0].map{"\($0)"}.reduce(""){$0+$1}

but I cannot figure out how would I convert an array of Ints to a comma separated String

但我无法弄清楚如何将Ints数组转换为逗号分隔的String

1 个解决方案

#1


25  

Well you can do it like :

那么你可以这样做:

let formattedArray = ([0,1,1,0].map{String($0)}).joined(separator: ",")

#1


25  

Well you can do it like :

那么你可以这样做:

let formattedArray = ([0,1,1,0].map{String($0)}).joined(separator: ",")