将Ints数组转换为逗号分隔的字符串 [英] Convert an array of Ints to a comma separated string

查看:178
本文介绍了将Ints数组转换为逗号分隔的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,如果我想将Int的数组转换为String,我可以这样做:

I know that if I want to convert an array of Ints 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 Ints to a comma separated String

推荐答案

好吧,你可以这样做:

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

这篇关于将Ints数组转换为逗号分隔的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆