Swift split string at first match of a character

前端 未结 3 1630
粉色の甜心
粉色の甜心 2020-12-20 15:37

I\'m trying to make an iOS app in Swift that requires me to split a line of text at the first colon (:) of a line. I\'ve tried using the the componentsSeparatedByString meth

3条回答
  •  不思量自难忘°
    2020-12-20 15:47

    Swift 4.2, Swift 5 answer:

    let str = "Hello, this is, a,  playground"
    let splitStringArray = str.split(separator: ",", maxSplits: 1).map(String.init)
    
    print(splitStringArray) // ["Hello", " this is, a,  playground"]
    

提交回复
热议问题