split
Builtin index · Collections & strings
result = split(s, delim, [limit])
Input: s, delim, limit · Output: result
What it is
s and delim are Strs; optional limit (number of pieces, default: unlimited) stops after that many pieces and leaves the remainder undivided as the last one — split(line, ": ", 2) takes key: value with: colons apart that way.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = split(s, delim, [limit]) | s Strs and delim are Strs.delim Strs and delim are Strs.limit number, optionaloptional limit (number of pieces, default: unlimited) stops after that many pieces and leaves the remainder undivided as the last one — split(line, ": ", 2) takes key: value with: colons apart that way. | result List or Str | Returns a List of Str. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
for line in lines(trim(txt))
parts = split(line, ",")
print(" {parts[0]} -> {parts[1]}")
end for
from agent-guide
s = " Hello, Qu World! "
trimmed = trim(s)
parts = split(trimmed, ", ")
print(parts) # ["Hello", "Qu World!"]
print(upper(parts[0])) # HELLO
print(starts_with(trimmed, "Hello")) # true
print("hello".substr(0, 2).replace("e", "i").flip().flip())
print("hi world".split(" ").join(", ") + "!")
output
("Hello", "Qu World!")
HELLO
true
hi
hi, world!from collections-strings