String

Overview

A String value natively represents a sequence of text. Characters may consist of multiple codepoints, which has a length denoted by the .size method and a .bytes method for the underlying length.

Fields

.size

fn -> Number

Gets the size of a String in UTF-8 codepoints.

.bytes

fn -> Number

Gets the size of a String in bytes.

.symbol

fn -> Symbol

Gets the hashed Symbol of a String value.

.empty

fn -> Boolean

Determines if a String has no codepoints.

.at

fn (index: Number) -> String

Gets a codepoint of a String by index.

.slice

fn (start?: Number, end?: Number) -> String

Creates a section of a String indicated by a given range.

.compare

fn (other: String) -> Number

Compares the difference between a String and another.

.contains

fn (needle: String, index?: Number) -> Number

Determines if a String contains a matching needle value.

.starts_with

fn (needle: String) -> Boolean

Determines if a String starts with a matching needle value.

.ends_with

fn (needle: String) -> Boolean

Determines if a String ends with a matching needle value.

.to_lower

fn -> String

Converts a String to lower-case.

.to_upper

fn -> String

Converts a String to upper-case.

.trim_both

fn -> String

Removes all leading and trailing whitespace.

.trim_leading

fn -> String

Removes any leading whitespace.

.trim_trailing

fn -> String

Removes any trailing whitespace.

.pad_leading

fn (length: Number, padding?: String) -> String

Pads a String shorter than the length with a given padding from the left.

.pad_trailing

fn (length: Number, padding?: String) -> String

Pads a String shorter than the length with a given padding from the right.

.fmt

fn (...args: Any) -> String

Formats a String using the fmt library.

Statics

.from

fn (value: Any) -> String

Converts a given value into it's String representation

.codepoint

fn (rune: Number) -> String

Creates a String from a given numerical codepoint.

On this page