Swift 4.0
数组转字符串
let array = ["a", "b", "c"]
let s = array.joined(separator: ",")
print(s)
// 结果为:a,b,c
Swift 2.0
字符串转数组
let str = "1,2,3"
let array = str.componentsSeparatedByString(",")
数组转字符串
let array = ["1", "2", "3"]
let str = ",".join(array)
// or
let str = array.joinWithSeparator(",")
Swift Dev for MacOS
网友评论