Skip to content
Try Kata

native.Str

Native methods on Str.

All modules · Writing docstrings

func len(self: Str): Int

Returns the number of Unicode codepoints.

func contains(self: Str, needle: Str): Bool

Returns whether the string contains needle.

func starts_with(self: Str, prefix: Str): Bool

Returns whether the string starts with prefix.

func ends_with(self: Str, suffix: Str): Bool

Returns whether the string ends with suffix.

func trim(self: Str): Str

Removes leading and trailing whitespace.

func trim_start(self: Str): Str

Removes leading whitespace.

func trim_end(self: Str): Str

Removes trailing whitespace.

func to_upper(self: Str): Str

Returns an uppercase string.

func to_lower(self: Str): Str

Returns a lowercase string.

func replace(self: Str, from: Str, to: Str): Str

Replaces all occurrences of from with to.

func substr(self: Str, start: Int, len: Int): Str

Returns 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.

func to_int(self: Str): Int

Parses trimmed text as Int; invalid input errors.

func to_float(self: Str): Float

Parses trimmed text as Float; invalid input errors.

func to_bin(self: Str): Bin

Encodes the string as UTF-8 bytes.

func chars(self: Str): Arr[Char]

Returns an array of Unicode characters.

func hash(self: Str): U64

Returns this string’s runtime hash.