githubEdit

String Library (Str)

Linked with the "str" type.

Example Usage

#[main]
fn main() {
    assert_eq("hello, world".split(", "), ['hello', 'world']);
}

Str.at(val: str, index: int) -> str

Returns a character at the given index within the string, or the last character if the index is out of bounds.

const val = "hello";
assert_eq(val[1], "e");

Str.contains(val: str, seq: str) -> bool

Return true if the sequence is found at least once anywhere in this string.

const val = "hello, world";
assert(val.contains(", w"));

Str.ends_with(val: str, seq: str) -> bool

Does this string end with the given string sequence?

Str.first(val: str) -> str

Return the first char (as a string) in this string.

Str.index_of(val: str, seq: str) -> int

Find the first occurrance of the given sequence in this string, returning the index of the first char. If not found, returns -1.

Str.last(val: str) -> str

Return the last char (as a string) in this string.

Str.len(val: str) -> int

Returns the length (number of characters) in this string.

Str.lower(val: str) -> str

Return a new string with all characters converted to lowercase.

Str.push(val: str, other: str) -> void

Pushes another string to the back of this string, leaving the other string unmodified.

Str.replace(val: str, find: str, replace: str = "") -> str

Replace all occurrances of a find string with a replace string (default removes all occurrances). This will return a new string, without modifying the original.

Str.split(val: str, sep: str = " ") -> list

Splits a string into a list at the given separator.

Str.starts_with(val: str, seq: str) -> bool

Does this string start with the given string sequence?

Str.substring(val: str, start: int = 0, end: int = -1) -> str

Return a new string that is the substring of the given value from a start index up to, but not including an end index. Default start is the beginning of the string and the default end is the entire length of the string.

Str.trim(val: str) -> str

Return a new string with the whitespace (newlines, tabs, and space characters) removed from the front and back.

Str.trim_end(val: str) -> str

Return a new string with the whitespace (newlines, tabs, and space characters) removed from the back only.

Str.trim_start(val: str) -> str

Return a new string with the whitespace (newlines, tabs, and space characters) removed from the front only.

Str.upper(val: str) -> str

Return a new string with all characters converted to uppercase.

Last updated