2019年6月27日 星期四

iOS swift 5: 字串的切割分離

iOS swift 5: 字串的切割分離

 解決方案來源:
  A Unicode string value that is a collection of characters.
  Swift Arrays
  Split a String into an array in Swift?

字串的切割分離
import Foundation
let fullName : String = "First Last";
let fullNameArr : [String] = fullName.componentsSeparatedByString(" ")

// And then to access the individual words:

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


  let sStr:String = "0,0001,0010,0100,1000,1023,0001,0001,0001"
  
  let sStrArr = sStr.components(separatedBy: ",")
  print( sStrArr.count )
  print( sStrArr[0] )
  ...
  print( sStrArr[6] )









沒有留言:

張貼留言