Home / Docs / Standard library / Prelude

trim

Release v0.4.0Edition 0.1 and later

A function of the prelude, in scope in every module. Edition 0.1 and later.

una
pub trim(t: Text) -> Text
  ensures result.len <= t.len

t without the Unicode whitespace at both ends (spec/14 §1).

Parameters

Returns

Text: t without the Unicode White_Space at both ends; never longer than t.

Use instead

Example

src/shop.unauna
module shop

--- A product name typed with spaces around it.
pub main() -> Unit
  uses @console: Console[print]
=
  let name = "  Desk lamp  ".trim()
  @console.print("[{name}]")

una run . prints:

Output
[Desk lamp]

Specification

Generated from the standard modules of una v0.4.0 (docs/std/listing.json, which is not part of the specification). The specification governs: spec/14 §1.