In Swift, can you split a string by another string, not just a character?

前端 未结 2 1839
情书的邮戳
情书的邮戳 2020-12-11 14:54

In Swift, it\'s easy to split a string on a character and return the result in an array. What I\'m wondering is if you can split a string by another string instead of just

2条回答
  •  执笔经年
    2020-12-11 15:19

    You mean this?

    let developer = "XCode Swift"
    let array = developer.characters.split{" "}.map(String.init)
    
    array[0] // XCode
    array[1] // Swift
    

提交回复
热议问题