native.Str
Native methods on Str.
All modules · Writing docstrings
func len(self: Str): IntReturns the number of Unicode codepoints.
contains
Section titled “contains”func contains(self: Str, needle: Str): BoolReturns whether the string contains needle.
starts_with
Section titled “starts_with”func starts_with(self: Str, prefix: Str): BoolReturns whether the string starts with prefix.
ends_with
Section titled “ends_with”func ends_with(self: Str, suffix: Str): BoolReturns whether the string ends with suffix.
func trim(self: Str): StrRemoves leading and trailing whitespace.
trim_start
Section titled “trim_start”func trim_start(self: Str): StrRemoves leading whitespace.
trim_end
Section titled “trim_end”func trim_end(self: Str): StrRemoves trailing whitespace.
to_upper
Section titled “to_upper”func to_upper(self: Str): StrReturns an uppercase string.
to_lower
Section titled “to_lower”func to_lower(self: Str): StrReturns a lowercase string.
replace
Section titled “replace”func replace(self: Str, from: Str, to: Str): StrReplaces all occurrences of from with to.
substr
Section titled “substr”func substr(self: Str, start: Int, len: Int): StrReturns up to len codepoints beginning at start; negative or out-of-range indexes error.
func split(self: Str, separator: Str): Arr[Str]Splits the string into an array of strings.
to_int
Section titled “to_int”func to_int(self: Str): IntParses trimmed text as Int; invalid input errors.
to_float
Section titled “to_float”func to_float(self: Str): FloatParses trimmed text as Float; invalid input errors.
to_bin
Section titled “to_bin”func to_bin(self: Str): BinEncodes the string as UTF-8 bytes.
func chars(self: Str): Arr[Char]Returns an array of Unicode characters.
func hash(self: Str): U64Returns this string’s runtime hash.