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