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(s: String, start: Scalar, end: Scalar) -> String
Examples
str_slice("Numbat", 3, 6)
= "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
str_append("Numbat", "!")
= "Numbat!" [String]
str_find
Find the first occurrence of a substring in a string.
fn str_find(haystack: String, needle: String) -> Scalar
Examples
str_find("Numbat is a statically typed programming language.", "typed")
= 23
str_contains
Check if a string contains a substring.
fn str_contains(haystack: String, needle: String) -> Bool
Examples
str_contains("Numbat is a statically typed programming language.", "typed")
= true [Bool]
str_replace
Replace all occurrences of a substring in a string.
fn str_replace(s: String, pattern: String, replacement: String) -> String
Examples
str_replace("Numbat is a statically typed programming language.", "statically typed programming language", "scientific calculator")
= "Numbat is a scientific calculator." [String]
str_repeat
Repeat the input string n
times.
fn str_repeat(a: String, n: Scalar) -> String
Examples
str_repeat("abc", 4)
= "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]