Split string with separator of another string

How can I split string with separator of another string or multiple characters?

let s = "#! it #! happens #! sometimes"
s.split(separator: "#!")

Thanks

There's a method in Foundation that does what you want

import Foundation

let s = "#! it #! happens #! sometimes"
print(s.components(separatedBy: "#!")) // ["", " it ", " happens ", " sometimes"]
1 Like

Thanks.
Now, I can find it under StringProtocol