Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

10.3 Text functions

Positions count characters, not bytes; a negative start counts from the end. Text functions expect strings: a null, a number or a missing field is an error (`upper` expects a string, found Null), except where noted. Convert first with to_string, or guard with coalesce(x?, "").


len

len(x) → the characters of a string, the items of an array, or the keys of an object.

len("Élodie")      → 6
len(tags)          → 2
len(profile)       → 2
where len(join_1) == 1

lower

lower(s) → s in lower case (Unicode).

upper

upper(s) → s in upper case (Unicode).

upper(trim(name))

trim

trim(s) → s without leading and trailing white space.

trim("  x ")       → "x"

ltrim

ltrim(s) → s without leading white space.

rtrim

rtrim(s) → s without trailing white space.

concat

concat(a, b, …) → the arguments joined as text. Numbers and booleans are written as text; null is skipped. When every argument is an array, the arrays are concatenated instead.

concat(name, "@", lower(city))
concat("x", true, 2.5)     → "xtrue2.5"
concat("a", null, 1)       → "a1"
concat([1], [2])           → [1,2]
concat(tags, ["new"])

contains

contains(x, y) → for strings, whether y is a substring of x; for arrays, whether y is an item.

contains("Paris", "ar")    → true
contains(tags, "dev")

starts_with

starts_with(s, prefix) → whether s begins with prefix. In a lookup, starts_with(outer, joined) is indexed (longest-prefix rules).

starts_with(account, "60")

ends_with

ends_with(s, suffix) → whether s ends with suffix.

ends_with("abc", "bc")     → true

substr

substr(s, start [, length]) → the substring from start (0-based; negative from the end), up to length characters (to the end without it).

substr("Paris", 0, 3)      → "Par"
substr("Paris", 2)         → "ris"
substr("Ab", -1)           → "b"
substr(period, 0, 4) as year

split

split(s, separator) → the array of parts. An empty separator splits into characters.

split("a,b", ",")          → ["a","b"]
split("Ab", "")            → ["A","b"]

replace

replace(s, from, to) → s with every occurrence of from replaced by to.

replace("a-b-c", "-", "+")     → "a+b+c"

index_of

index_of(x, y) → the position of y in a string or an array, -1 when absent.

index_of("Ab", "b")        → 1
index_of(tags, "dev")      → 1

pad_left

pad_left(s, width [, fill]) → s padded on the left to width characters with fill (a space by default).

pad_left(to_string(qty), 3, "0")   → "003"

pad_right

pad_right(s, width [, fill]) → s padded on the right.

pad_right("ab", 4)         → "ab  "

reverse

reverse(x) → a string or an array reversed. See arrays.


Comparison of text is by code point: "10" < "9" is true. Compare numbers as numbers (to_int, to_float), and dates as ISO strings of one shape or as epoch milliseconds.