在Swift中將字符串拆分紅數組? - Split a String into an array in Swift?

問題:

Say I have a string here: 說我在這裏有一個字符串: 數組

var fullName: String = "First Last"

I want to split the string base on white space and assign the values to their respective variables 我想在空白處分割字符串並將值分配給它們各自的變量 spa

var fullNameArr = // something like: fullName.explode(" ") 

var firstName: String = fullNameArr[0]
var lastName: String? = fullnameArr[1]

Also, sometimes users might not have a last name. 一樣,有時用戶可能沒有姓氏。 .net


解決方案:

參考一: https://stackoom.com/question/1jk7J/在Swift中將字符串拆分紅數組
參考二: https://oldbug.net/q/1jk7J/Split-a-String-into-an-array-in-Swift
相關文章
相關標籤/搜索