String-related functions
Defined in: core::strings
str_length
The length of a string.
fn str_length(s: String) -> Scalar
Examples
str_length("Numbat")
= 6
str_slice
Subslice of a string.
fn str_slice(start: Scalar, end: Scalar, s: String) -> String
Examples
str_slice(3, 6, "Numbat")
= "bat" [String]
chr
Get a single-character string from a Unicode code point.
fn chr(n: Scalar) -> String
Examples
0x2764 -> chr
= "❤" [String]
ord
Get the Unicode code point of the first character in a string.
fn ord(s: String) -> Scalar
Examples
"❤" -> ord
= 10084
lowercase
Convert a string to lowercase.
fn lowercase(s: String) -> String
Examples
lowercase("Numbat")
= "numbat" [String]
uppercase
Convert a string to uppercase.
fn uppercase(s: String) -> String
Examples
uppercase("Numbat")
= "NUMBAT" [String]
str_append
Concatenate two strings.
fn str_append(a: String, b: String) -> String
Examples
"Numbat" |> str_append("!")
= "!Numbat" [String]
str_prepend
Concatenate two strings.
fn str_prepend(a: String, b: String) -> String
Examples
"!" |> str_prepend("Numbat")
= "!Numbat" [String]
str_find
Find the first occurrence of a substring in a string.
fn str_find(needle: String, haystack: String) -> Scalar
Examples
str_find("typed", "Numbat is a statically typed programming language.")
= 23
str_contains
Check if a string contains a substring.
fn str_contains(needle: String, haystack: String) -> Bool
Examples
str_contains("typed", "Numbat is a statically typed programming language.")
= true [Bool]
str_replace
Replace all occurrences of a substring in a string.
fn str_replace(pattern: String, replacement: String, s: String) -> String
Examples
str_replace("statically typed programming language", "scientific calculator", "Numbat is a statically typed programming language.")
= "Numbat is a scientific calculator." [String]
str_repeat
Repeat the input string n
times.
fn str_repeat(n: Scalar, a: String) -> String
Examples
str_repeat(4, "abc")
= "abcabcabcabc" [String]
base
Convert a number to the given base.
fn base(b: Scalar, x: Scalar) -> String
Examples
42 |> base(16)
= "2a" [String]
bin
Get a binary representation of a number.
fn bin(x: Scalar) -> String
Examples
42 -> bin
= "0b101010" [String]
oct
Get an octal representation of a number.
fn oct(x: Scalar) -> String
Examples
42 -> oct
= "0o52" [String]
dec
Get a decimal representation of a number.
fn dec(x: Scalar) -> String
Examples
0b111 -> dec
= "7" [String]
hex
Get a hexadecimal representation of a number.
fn hex(x: Scalar) -> String
Examples
2^31-1 -> hex
= "0x7fffffff" [String]