str.split()

let str = " rabbit,  dog, cat, elephant , elf "

// โญ๏ธ single separator
str.split(separator: ",")
// โญ๏ธ Note: spaces are NOT removed.
// [" rabbit", "  dog", " cat", " elephant ", " elf "]

// โญ๏ธ multiple separators
str.split {$0 == "," || $0 == " "}
// ["rabbit", "dog", "cat", "elephant", "elf"]

โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”

Last updated