swift 合并数组、拆分字符串

2017-10-19  本文已影响0人  iqqq
// 合并字符串数组
let arr1: [String] = ["1", "", "1", "2"]
arr1.joined(separator: "|")  // 1||1|2

// 合并整型数组
let arr2: [Int] = [1, 2, 3, 4]
arr2.map(String.init).joined(separator: "|")

// 拆分字符串
let str1: String = "1,2,,,,3"
str1.split(separator: ",")  // ["1", "2", "3"]
str1.components(separatedBy: ",")  // ["1", "2", "", "", "", "3"]

上一篇 下一篇

猜你喜欢

热点阅读