Skip to content

Strings

Format, split, join, trim and transform strings.

chomp

chomp(str) → string

Remove trailing newlines from a string.

ParameterTypeDescription
strstring

format

format(format, args...) → string

Format a string using printf-style verbs.

ParameterTypeDescription
formatstring
args...anyVariadic.
format("hello %s, you are %d", "alice", 30)

→ "hello alice, you are 30"

formatlist

formatlist(format, args...) → list(string)

Format each element of a list using printf-style verbs.

ParameterTypeDescription
formatstring
args...anyVariadic.

join

join(separator, list) → string

Join a list of strings with a separator.

ParameterTypeDescription
separatorstring
listlist(string)
join(", ", ["a", "b", "c"])

→ "a, b, c"

lower

lower(str) → string

Convert a string to lowercase.

ParameterTypeDescription
strstring
lower("HELLO")

→ "hello"

replace

replace(str, old, new) → string

Replace all occurrences of a substring.

ParameterTypeDescription
strstring
oldstring
newstring

split

split(separator, str) → list(string)

Split a string by a separator.

ParameterTypeDescription
separatorstring
strstring
split(",", "a,b,c")

→ ["a", "b", "c"]

strlen

strlen(str) → number

Return the length of a string in characters.

Use length for collections (lists, maps, tuples). strlen is for strings only.

ParameterTypeDescription
strstring

substr

substr(str, offset, length) → string

Extract a substring by offset and length.

ParameterTypeDescription
strstring
offsetnumber
lengthnumber

title

title(str) → string

Convert a string to title case.

ParameterTypeDescription
strstring
title("hello world")

→ "Hello World"

trim

trim(str, cutset) → string

Remove leading and trailing characters from a string.

ParameterTypeDescription
strstring
cutsetstringCharacters to remove.

trimprefix

trimprefix(str, prefix) → string

Remove a prefix from the start of a string.

ParameterTypeDescription
strstring
prefixstring

trimspace

trimspace(str) → string

Remove leading and trailing whitespace from a string.

ParameterTypeDescription
strstring

trimsuffix

trimsuffix(str, suffix) → string

Remove a suffix from the end of a string.

ParameterTypeDescription
strstring
suffixstring

upper

upper(str) → string

Convert a string to uppercase.

ParameterTypeDescription
strstring
upper("hello")

→ "HELLO"