types.String.split_by_chars
Splits str into an array of strings at every byte that occurs in separators.
The binding carries no declaration string, so the VM cannot report parameter names. The names above are from this page; the types and attributes still come from the VM. The VM also cannot tell an optional parameter from a variadic tail here, so read the brackets and any trailing
... from the prose below, not from the signature.let inventory = "sword,shield,potion"
println("inventory.split_by_chars(\",\") joined =", ",".join(inventory.split_by_chars(",")))Output:
inventory.split_by_chars(",") joined = sword,shield,potionParameters
separators | string | the set of bytes that split str, each one its own separator, not a substring to match as a whole |
skip_empty | bool | when true, a piece with zero bytes is left out of the result instead of being added as "" optional |
... | any | repeats |
Return value
An array of the pieces of str, in order, with every separator byte removed. See string.split_by_chars for the exact rules on leading, trailing and repeated separators.
Errors
Throws empty separators string when separators is "".
Notes
Takes 1 or 2 arguments: skip_empty is optional and defaults to false. Same implementation as string.split_by_chars; see the Notes on types.String.strip for how the two forms differ only in their reported attributes, not their behavior.
Contrast types.String.split, whose separator is a literal substring matched as a whole rather than a set of individual bytes.
Example
println("\"a,,b,\".split_by_chars(\",\") joined =", ",".join("a,,b,".split_by_chars(","))) // trailing separator: no trailing empty
println("\"a,,b,\".split_by_chars(\",\", true) joined =", ",".join("a,,b,".split_by_chars(",", true))) // skip_empty drops the middle piece tooOutput:
"a,,b,".split_by_chars(",") joined = a,,b
"a,,b,".split_by_chars(",", true) joined = a,bSee also
split | Splits str into an array of strings. |
split_by_chars | Splits str into an array of strings at every character that occurs in separators. |
| string | class index |