Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

Trim

Removes leading Unicode whitespace from a borrowed UTF-8 view.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

Module std.text

import std.text;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

fn

pub const fn TrimStart(Text: str) -> str

Removes leading Unicode whitespace from a borrowed UTF-8 view. Text: Valid UTF-8 backing storage, borrowed by the returned view. Return: Boundary-aligned suffix; allocates nothing and retains no owner. Warning: The result expires when the original backing storage is invalidated.

Example

module example.text_trimming;
from std.text import Trim, TrimStart, TrimEnd;
fn Main() -> i32 {
    let Text: str = "\u{2003} λ \u{00A0}";
    if Trim(Text) != "λ" { return 1; }
    if TrimStart(Text) != "λ \u{00A0}" { return 2; }
    if TrimEnd(Text) != "\u{2003} λ" { return 3; }
    if Trim(" \t\u{3000}") != "" || Trim("") != "" { return 4; }
    if Trim("\u{200B}λ\u{FEFF}") != "\u{200B}λ\u{FEFF}" { return 5; }
    return 0;
}

fn

pub const fn TrimEnd(Text: str) -> str

Removes trailing Unicode whitespace from a borrowed UTF-8 view. Text: Valid UTF-8 backing storage, borrowed by the result. Return: Boundary-aligned prefix after backward tail traversal, with no allocation. Warning: The result expires with its original backing storage.

fn

pub const fn Trim(Text: str) -> str

Removes leading and trailing Unicode whitespace without changing interior bytes. Text: Valid UTF-8 backing storage, borrowed by the result. Return: Borrowed boundary-aligned view after leading/trailing whitespace scans, no allocation. Warning: The result expires with its original backing storage.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library