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

# split

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

```una
pub split(t: Text, on: Text) -> List[Text]
  requires on.len > 0
  ensures result.len >= 1
```

The parts of `t` between the non-overlapping occurrences of `on`, left to right (`spec/22 §2`).

## Parameters

- `t`: the text
- `on`: the separator

## Returns

`List[Text]`: the parts of `t` between the non\-overlapping occurrences of `on`\, left to right\, empty parts included\; at least one part.

## Requires

- `on.len > 0`: the separator is not empty

Each condition under `requires` is an obligation at every call\, which `una check` proves \(`spec/12 §3`\)\: it reports U5001 when the condition is refuted and U5002 when it is unknown \(`spec/12 §6`\)\, and `una run`\, `una test` and `una build` refuse a package with an obligation that is not proved \(`spec/22 §2`\)\.

## See also

[`join`](https://una-lang.org/en/docs/std/prelude/join/), [`find`](https://una-lang.org/en/docs/std/prelude/find/)

## Cost

Time `O(b + m), two-way search` (ADR 0070), where:

- `b`: the length of `t` in UTF\-8 bytes
- `m`: the length of `on` in UTF\-8 bytes

## Example

`src/shop.una`

```una
module shop

--- The fields of an order line: SKU, quantity, price in cents.
pub main() -> Unit
  uses @console: Console[print]
=
  for field in "CAFÉ-01,2,1999".split(on: ",")
    @console.print(field)
```

`una run .` prints:

```text
CAFÉ-01
2
1999
```

## Specification

- [`spec/22 §2`](https://una-lang.org/en/docs/spec/22-text/#s2)

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).
