Swift根据字符切割字符串为数组

Swift 2: Xcode 7

let fullName = "First Last"
let fullNameArr = fullName.characters.split{$0 == " "}.map(String.init)
// or simply:
// let fullNameArr = fullName.characters.split{" "}.map(String.init)

fullNameArr[0] // First
fullNameArr[1] // Last

你可能感兴趣的:(Swift根据字符切割字符串为数组)