---
title: "trim"
url: https://una-lang.org/en/docs/std/prelude/trim/
release: v0.4.0
edition: "0.1 and later"
source: https://github.com/una-lang/una/blob/v0.4.0/docs/std/listing.json
---

# trim

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

- `t`: the text

## Returns

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

## Use instead

- [`trim_start`](https://una-lang.org/en/docs/std/prelude/trim_start/) (edition 0.2 on) to keep the Unicode `White_Space` at the end
- [`trim_end`](https://una-lang.org/en/docs/std/prelude/trim_end/) (edition 0.2 on) to keep the Unicode `White_Space` at the start

## Example

`src/shop.una`

```una
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:

```text
[Desk lamp]
```

## Specification

- [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1)

Generated from the standard modules of una v0.4.0 ([`docs/std/listing.json`](https://github.com/una-lang/una/blob/5fec93d88932b333feec25e589355a2cb34c37b5/docs/std/listing.json), which is not part of the specification). The specification governs: [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1).
