Split the string based on space iOS swift || Split string and save in an array iOS swift
Solution:
We can easily split the string value based on space and save it into an array using the split function like below
In swift:
We can easily split the string value based on space and save it into an array using the split function like below
In swift:
var namStr = "First Middle last"
var nameArr = split(namStr) {$0 == " "}
nameArr[0]//First
nameArr[1]//Middle
nameArr[2]//last
In swift 2:
var namStr = "First Middle last"
let nameArrVal = namStr.characters.split{$0 == " "}.map(String.init)
Comments
Post a Comment