xur_

> module

std::str

string methods

use std::str; in the browser

The methods below are on string values. They are available on any str value directly, without importing a module. The std::str module adds the chr function and the str::Error type.

Strings are UTF-8. Lengths, indices and offsets count characters (Unicode scalar values), not bytes: "αβ".len() is 2. Strings never change; methods that edit return a new string.

slice, insert and remove take indices that may be negative, counting from the end: -1 is the position before the last character. Indices past either end are clamped to the string, so these methods never fail.

> functions

# chr(codepoint: u32) -> Result<str, Error>

The one-character string for the Unicode codepoint codepoint: str::chr(65) is "A". A surrogate or a value above 0x10FFFF gives Err(str::Error::InvalidCodepoint).

> types

┌ enum Error

A recoverable string error. Match it as `Err(str::Error::Parse)` etc.

Error::InvalidCodepoint`chr`: the integer is not a valid Unicode codepoint.
Error::NotSingleChar`ord`: the string is not exactly one character.
Error::Parse`parse_int`/`parse_hex`/`parse_float`: not a valid number.

> errors

str::Error is an enum to match on: InvalidCodepoint (str::chr), NotSingleChar (ord) and Parse (parse_int, parse_hex, parse_float).

> examples

use std::io;

fn main() {
    let s = "  Hello, World!  ";
    io::println("{}", s.trim());
    io::println("{}", s.trim().to_upper());
    io::println("{}", "a,b,c".split(",").join(" | "));
    io::println("{}", "42".parse_int().unwrap());
}