Qu

lines

Builtin index · Collections & strings

result = lines(s)

Input: s · Output: result

What it is

s is a Str. Splits on either line ending, with no spurious empty last element when the text ends in a newline.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = lines(s)
s Strnot documented yet
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

text = "one\ntwo\nthree"
print(lines(text))                     # ("one", "two", "three")

print(chars("abc"))                    # ("a", "b", "c")

print(repeat_str("ab", 3))             # "ababab"

print(as_text([1, 2, 3]).join(", "))   # "1, 2, 3"

output
("one", "two", "three")
("a", "b", "c")
ababab
1, 2, 3

from collections-strings

How it works

lines(s) — split into lines, tolerating either line ending, and WITHOUT a spurious empty last line when the text ends in a newline (which it usually does, and which split(s, "\n") gives you).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.