Swift-数组与字符串转换

作者: FlyElephant | 来源:发表于2017-11-22 18:52 被阅读333次

    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)")
    

    相关文章

      网友评论

      • Fuuqiu:swift let dataStr = data.map(String.init)
        let result = dataStr.joined(separator: ",")报错

      本文标题:Swift-数组与字符串转换

      本文链接:https://www.haomeiwen.com/subject/attwrxtx.html