将 Int 数组转换为逗号分隔的字符串 [英] Convert an array of Ints to a comma separated string
本文介绍了将 Int 数组转换为逗号分隔的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如果我想将 Int
的数组转换为 String
,我这样做:
I know that if I want to convert an array of Int
s to a String
, I do this:
[0,1,1,0].map{"\($0)"}.reduce(""){$0+$1}
但我不知道如何将 Int
数组转换为逗号分隔的 String
but I cannot figure out how would I convert an array of Int
s to a comma separated String
推荐答案
你可以这样做:
let formattedArray = ([0,1,1,0].map{String($0)}).joined(separator: ",")
这篇关于将 Int 数组转换为逗号分隔的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文