String manipulation. auto-imported.
Remove leading and trailing whitespace.
string.trim(" hello ") // => "hello"
Split a string by separator into a list of substrings.
string.split("a,b,c", ",") // => ["a", "b", "c"]
Join a list of strings with a separator.
string.join(["a", "b", "c"], "-") // => "a-b-c"
Return the number of characters in a string.
string.len("hello") // => 5
Check if a string contains a substring.
string.contains("hello world", "world") // => true
Check if a string starts with a prefix.
string.starts_with("hello", "hel") // => true
Check if a string ends with a suffix.
string.ends_with("hello", "llo") // => true
Extract a substring by codepoint start and optional end index.
string.slice("hello", 1, 4) // => "ell"
Pad a string on the left to reach a target length.
string.pad_start("42", 5, "0") // => "00042"
Convert a string to a list of UTF-8 byte values.
string.to_bytes("Hi") // => [72, 105]
Capitalize the first character of a string.
string.capitalize("hello") // => "Hello"
Convert all characters to uppercase.
string.to_upper("hello") // => "HELLO"
Convert all characters to lowercase.
string.to_lower("HELLO") // => "hello"
Replace all occurrences of a substring.
string.replace("aabbcc", "bb", "XX") // => "aaXXcc"
Get the character at a given codepoint index, or none if out of bounds.
string.get("hello", 1) // => some("e")
Split a string into lines.
string.lines("a\nb\nc") // => ["a", "b", "c"]
Split a string into individual characters.
string.chars("abc") // => ["a", "b", "c"]
Find the first codepoint index of a substring, or none if not found.
string.index_of("hello", "ll") // => some(2)
Repeat a string n times.
string.repeat("ab", 3) // => "ababab"
Create a string from a list of UTF-8 byte values.
string.from_bytes([72, 105]) // => "Hi"
Check if all characters are ASCII digits.
string.is_digit("123") // => true
Check if all characters are alphabetic.
string.is_alpha("abc") // => true
Check if all characters are alphanumeric.
string.is_alphanumeric("abc123") // => true
Check if all characters are whitespace.
string.is_whitespace(" ") // => true
Check if all characters in the string are uppercase.
string.is_upper("ABC") // => true
Check if all characters in the string are lowercase.
string.is_lower("abc") // => true
Return the Unicode codepoint of the first character, or none for empty string.
string.codepoint("A") // => some(65)
Create a single-character string from a Unicode codepoint.
string.from_codepoint(65) // => "A"
Pad a string on the right to reach a target length.
string.pad_end("hi", 5, ".") // => "hi..."
Remove leading whitespace.
string.trim_start(" hello") // => "hello"
Remove trailing whitespace.
string.trim_end("hello ") // => "hello"
Count occurrences of a substring.
string.count("banana", "an") // => 2
Check if a string is empty.
string.is_empty("") // => true
Reverse the characters in a string.
string.reverse("hello") // => "olleh"
Remove a prefix if present, returning none if not found.
string.strip_prefix("hello", "hel") // => some("lo")
Remove a suffix if present, returning none if not found.
string.strip_suffix("hello", "llo") // => some("he")
Replace the first occurrence of a substring.
string.replace_first("aabaa", "a", "X") // => "Xabaa"
Find the last codepoint index of a substring, or none if not found.
string.last_index_of("abcabc", "bc") // => some(4)
Get the first character of a string.
string.first("hello") // => some("h")
Get the last character of a string.
string.last("hello") // => some("o")
Take the first N characters.
string.take("hello", 3) // => "hel"
Take the last N characters.
string.take_end("hello", 3) // => "llo"
Drop the first N characters.
string.drop("hello", 2) // => "llo"
Drop the last N characters.
string.drop_end("hello", 2) // => "hel"