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

前端 未结 2 1836
情书的邮戳
情书的邮戳 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
    
    0 讨论(0)
  • 2020-12-11 15:25
    import Foundation
    
    let inputString = "This123Is123A123Test"
    let splits = inputString.components(separatedBy: "123")
    
    0 讨论(0)
提交回复
热议问题