Skip to content

String

fn length(s: String) -> Int

The number of user-perceived characters (grapheme clusters). "👍".length() is 1.

fn byte_size(s: String) -> Int

The number of bytes in UTF-8.

fn append(a: String, b: String) -> String

Joins two strings: "ab".append("cd") is "abcd".

fn concat(parts: List[String]) -> String

Joins all the strings in order: String.concat(["a", "b", "c"]) is "abc".

fn contains(s: String, sub: String) -> Bool

Matches by code point sequence.

fn starts_with(s: String, prefix: String) -> Bool

Whether s starts with prefix.

fn ends_with(s: String, suffix: String) -> Bool

Whether s ends with suffix.

fn split(s: String, sep: String) -> List[String]

Splits into grapheme clusters if sep is empty. s.split(sep).join(sep) == s holds.

fn chars(s: String) -> List[String]

One string per grapheme cluster.

fn join(parts: List[String], sep: String) -> String

Moved to List.join, so that it reads as parts.join(", ").

fn trim(s: String) -> String

Removes leading and trailing whitespace (Unicode White_Space).

fn code_points(s: String) -> List[Int]

The code point values of s, in order.

fn from_code_point(n: Int) -> Option[String]

None if n is not a Unicode scalar value (0 to 10FFFF, excluding surrogates).

fn show_nested[A: Show](value: A) -> String

The Show of a value shown inside another value ([trait.builtin]): a String is quoted and escaped ("a\"b"), any other type is its Show.show. For the Show impls in core ([1, 2], ["a"]).

fn to_ascii_lowercase(s: String) -> String

s with A to Z changed to a to z. Other characters, including non-ASCII letters, are left as they are.

fn to_ascii_uppercase(s: String) -> String

s with a to z changed to A to Z. Other characters, including non-ASCII letters, are left as they are.