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"]
// str.split(separator: ",")
func split(
separator: Character, // โญ๏ธ ๅฎไธๅ Character
maxSplits: Int = Int.max,
omittingEmptySubsequences: Bool = true
) -> [Substring]
// str.split() { char in ... }
func split(
maxSplits: Int = Int.max,
omittingEmptySubsequences: Bool = true,
// โญ๏ธ ๅฏไฝฟ็จๅคๅ Character
whereSeparator isSeparator: (Character) throws -> Bool
) rethrows -> [Substring]
Foundation (NSString bridged) โฉ String โฉ
string.components(separatedBy: CharacterSet) โ [String]
string.components(separatedBy: String) โ [String]
arr.split(where:) splits arrays into subarrays.
โโโโโโโโ
Last updated