Swift-数组与字符串转换

Swift 字符串转数组:

        let str = "I am FlyElephant"
        let array = str.components(separatedBy:" ")
        print("字符串转数组:\(array)")

Swift 数组转字符串:

        let data = [1, 2, 3, 4, 5]
        let dataStr = data.map(String.init)
        let result = dataStr.joined(separator: ",")
        print("数组转字符串:\(result)")

你可能感兴趣的:(Swift-数组与字符串转换)