Skip to content

String Functions

Concat

concatenates text arguments as strings

Syntax:

Concat(texts: ...string) -> string

Examples:

Concat("sc", "ow", "l") = "scowl"
"sc" + "ow" + "l" = "scowl"

Contains

returns whether text contains substring

Syntax:

Contains(text: string, substr: string) -> bool

Examples:

Contains("asdf", "sd") = true
("asdf" contains "ds") = false

EditDistance

returns the Levenshtein distance between two strings

Syntax:

EditDistance(x: string, y: string) -> int

Examples:

EditDistance("hello", "ello") = 1
EditDistance("j.christenson", "johnchristenson") = 4
EditDistance("asdfg", "hjklo") = 10

EndsWith

returns whether text ends with a suffix

Syntax:

EndsWith(text: string, suffix: string) -> bool

Examples:

EndsWith("fox", "ox") = true
EndsWith("five", "fi") = false

FakeEmbed

TODO: remove

Syntax:

FakeEmbed(text: string) -> [float]

Examples:

FakeEmbed("hello") = [0.2, 0.11, -0.3, ...

HasDigit

returns whether text contains one or more digits [0-9]

Syntax:

HasDigit(text: string) -> bool

Examples:

HasDigit("trustno1") = true
HasDigit("five") = false

HexEncode

encode integer as hexadecimal string

Syntax:

HexEncode(x: int) -> string

Examples:

HexEncode(59245) = "e76d"
HexEncode(-31) = "-1f"

Humanize

make data-oriented identifiers more human-readable

Syntax:

Humanize(text: string) -> string

Examples:

Humanize('__employee_salary')="Employee Salary"
Humanize('author-id')="Author Id"
Humanize('CREATE TIME')="Create Time"

Index

returns the lowest index in text where substr found. Returns -1 if not found

Syntax:

Index(text: string, substr: string) -> int

Examples:

Index("racecar", "ace") = 1
Index("racecar", "vroom") = -1

Interpolate

inserts values into format text

Syntax:

Interpolate(format: string, values: ...any) -> string

Examples:

Interpolate("%s is %d", "one", 1) = "one is 1"
Interpolate("%f rounded is %.2f", 1/3, 1/3) = "0.333333 rounded is 0.33"

Join

converts elements to text and joins them using the given separator

Syntax:

Join(sep: string, values: ...any) -> string

Examples:

Join("-", "one", "two", "three") = "one-two-three"
Join(".", "one", 2, 3.0) = "one.2.3"

Length

returns the number of characters in text

Syntax:

Length(text: string) -> int

Examples:

Length("hello") = 5
Length("🌎🌬🔥") = 3

Lower

converts text to lowercase

Syntax:

Lower(text: string) -> string

Examples:

Lower("HELLO") = "hello"
Lower("My 2 cents.") = "my 2 cents."

RegexFind

returns a string holding the text of the leftmost match of the regular expression

Syntax:

RegexFind(regex: string, text: string) -> string?

Examples:

RegexFind("foo.?", "seafood fool") = "food"
RegexFind("foo.?", "meat") is null

RegexMatch

reports whether the text contains any match of the regular expression

Syntax:

RegexMatch(regex: string, text: string) -> bool?

Examples:

RegexMatch("#[0-9a-f]{6}", "#a80f44") = true
RegexMatch("#[0-9a-f]{6}", "other") = false

RemoveNonAlpha

removes every character that is not a letter (a-z, A-Z)

Syntax:

RemoveNonAlpha(text: string) -> string

Examples:

RemoveNonAlpha("Fred.Smith_1985") = "FredSmith"
RemoveNonAlpha("$hello 🔥world!") = "helloworld"

RemoveNonAlphanumeric

removes every character that is not a letter (a-z, A-Z) or digit (0-9)

Syntax:

RemoveNonAlphanumeric(text: string) -> string

Examples:

RemoveNonAlphanumeric("Fred.Smith_1985") = "FredSmith1985"
RemoveNonAlphanumeric("$hello 🔥world!") = "helloworld"

Replace

replaces the first instance of old with new

Syntax:

Replace(text: string, old: string, new: string) -> string

Examples:

Replace("two by two", "two", "three") = "three by two"
Replace("scowl", "cow", "chicken") = "schickenl"
Replace("scowl", "dog", "cat") = "scowl"

ReplaceAll

replaces every non-overlapping instance of old with new

Syntax:

ReplaceAll(text: string, old: string, new: string) -> string

Examples:

ReplaceAll("two by two", "two", "three") = "three by three"
ReplaceAll("scowl", "cow", "chicken") = "schickenl"
ReplaceAll("scowl", "dog", "cat") = "scowl"

Repr

returns text representation of any value

Syntax:

Repr(x: any) -> string

Examples:

Repr("foo") = '"foo"'
Repr(45) = "45"
Repr(1.2) = "1.2"
Repr(false) = "false"
Repr(null) = "null"

Sha1

returns the hex digest of a SHA-1 hash of the text

Syntax:

Sha1(text: string) -> string

Examples:

Sha1("Hello, world!") = "943a702d06f34599aee1f8da8ef9f7296031d699"
Sha1("") = "da39a3ee5e6b4b0d3255bfef95601890afd80709"

Sha1Int

returns a 63-bit non-negative integer hash of the text

Syntax:

Sha1Int(text: string) -> int

Examples:

Sha1Int("Hello, world!") = 1457600768100222361
Sha1Int("") = 6501407781267655437

Simhash

returns the Simhash of the given text. Two inputs that are similar will result in Simhash values that are close in Hamming distance.

Syntax:

Simhash(text: string) -> string

Examples:

Simhash("This is spam") = "883a577eb7eb30c1"
Simhash("This is ham")  = "8812411ebfdb2c11"

Split

slices text into all substrings separated by sep and returns an array of the substrings between those separators

Syntax:

Split(text: string, <sep: string>) -> [string]

Examples:

Split("a   b  c d") = ["a", "b", "c", "d"]
Split("hello, world") = ["hello,", "world"]
Split("a-b--c", "-") = ["a", "b", "", "c"]
Split("hello, world", ", ") = ["hello", "world"]

StartsWith

returns whether text starts with a prefix

Syntax:

StartsWith(text: string, prefix: string) -> bool

Examples:

StartsWith("fox", "ox") = false
StartsWith("five", "fi") = true

String

converts argument to a string

Syntax:

String(x: any) -> string?

Examples:

String("foo") = "foo"
String(45) = "45"
String(1.2) = "1.2"
String(false) = "false"
String(null) is null

StringSimilarity

returns a similarity score for two strings: 0.0 (very different) to 1.0 (very similar) using the Levenshtein distance algorithm

Syntax:

StringSimilarity(x: string, y: string) -> float

Examples:

StringSimilarity("hello", "ello") = 0.8888888888888888
StringSimilarity("j.christenson", "johnchristenson") = 0.8571428571428571
StringSimilarity("asdfg", "hjklo") = 0

Strip

removes whitespace from front and end of text

Syntax:

Strip(text: string) -> string

Examples:

Strip(" hello world ") = "hello world"

Substr

returns the substring of s from start up to (optional) end

Syntax:

Substr(s: string, start: int, <end: int>) -> string

Examples:

Substr("scowl", 1) = "cowl"
Substr("scowl", 2, 4) = "ow"
Substr("scowl", 0, -2) = "sco"

Upper

converts text to uppercase

Syntax:

Upper(text: string) -> string

Examples:

Upper("hello") = "HELLO"
Upper("My 2 cents.") = "MY 2 CENTS."