概述直接上代码。 Swift 1 var fullName = "First Last"var fullNameArr = split(fullName) {$0 == " "}var firstName: String = fullNameArr[0]var lastName: String? = fullNameArr.count > 1 ? fullNameArr[1] : nil Swi @H_419_0@
直接上代码。 Swift 1 var fullname = "First Last"var fullnameArr = split(fullname) {$0 == " "}var firstname: String = fullnameArr[0]var lastname: String? = fullnameArr.count > 1 ? fullnameArr[1
] : nil Swift 2 Swift 2: Xcode 7 beta 1 let fullname = "First Last"let fullnameArr = split(fullname.characters){$0 == " "}.map{String($0)}fullnameArr[0] // FirstfullnameArr[1]// Last
Swift 2: Xcode 7 beta 2 let fullname = "First Last"let fullnameArr = split(fullname.characters){$0 == " "}.map(String.init)fullnameArr[0] // FirstfullnameArr[1]// Last
Swift 2: Xcode 7 beta 5 let fullname = "First Last"let fullnameArr = fullname.split {$0 == " "}fullnameArr[0] // FirstfullnameArr[1]// Last
Swift 2: Xcode 7 let fullname = "First Last"let fullnameArr = fullname.characters.split {$0 == " "}fullnameArr[0] // FirstfullnameArr[1]// Last
总结 以上是内存溢出为你收集整理的Swift 分割字符串
全部内容,希望文章能够帮你解决Swift 分割字符串所遇到的程序开发问题。
评论列表(0条)