trim
Builtin index · Collections & strings
result = trim(s, [chars])
Input: s, chars · Output: result
What it is
Strips characters from both ends of a string. s is a Str; optional chars (Str, default: whitespace) is a SET of characters to strip, not a substring — trim(field, "\"' ") strips quotes and spaces in any order from both ends.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = trim(s, [chars]) | s Strs is a Str.chars Str, optionaloptional chars (Str, default: whitespace) is a SET of characters to strip, not a substring — trim(field, "\"' ") strips quotes and spaces in any order from both ends. | result Str | Returns a Str. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
r = exec("echo hello from a program", shell = true)
print("said: {trim(r.stdout)}")
print("success {r.success}, exit code {r.exit_code}")
failed = exec("exit 3", shell = true)
print("a failure is data, not an error: success {failed.success}, code {failed.exit_code}")
said: hello from a program success true, exit code 0 a failure is data, not an error: success false, code 3
from file-io
for line in lines(trim(txt))
parts = split(line, ",")
print(" {parts[0]} -> {parts[1]}")
end for
from agent-guide
s = " Measurement Lane "
print("[{trim(s)}]") # [Measurement Lane]
print(upper(trim(s))) # MEASUREMENT LANE
print(contains(s, "Lane")) # true
print(replace(s, "Lane", "Window"))
[Measurement Lane] MEASUREMENT LANE true Measurement Window
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(", ") + "!")
("Hello", "Qu World!")
HELLO
true
hi
hi, world!from collections-strings
How it works
trim(s) removes whitespace; trim(s, chars) removes any of the characters in chars — a SET, not a substring, which is the meaning every language that has this gives it, and the one that makes trim(field, "\"' ") do what it looks like.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.