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

# find

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

```una
pub find(t: Text, text: Text) -> Option[Int]
```

The position of the first occurrence of `text` in `t`, `Some(0)` for an empty `text`; it is `Some` exactly when `contains_text(t, part: text)` (`spec/22 §2` rule 2).

## Parameters

- `t`: the text
- `text`: the text to look for

## Returns

`Option[Int]`: `Some` of the scalar position\, from 0\, of the first occurrence of `text` in `t`\, `Some(0)` for an empty `text`\, and `None` when it does not occur\; when it is `Some(p)`\, `0 <= p` and `p + text.len <= t.len`\, which the verifier assumes after each call.

## Use instead

- [`contains_text`](https://una-lang.org/en/docs/std/prelude/contains_text/) when only whether it occurs matters

## See also

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

## Cost

Time `O(b + m), plus O(1) for the scalar index from the checkpoints` (ADR 0070), where:

- `b`: the length of `t` in UTF\-8 bytes
- `m`: the length of `text` in UTF\-8 bytes
- index: on a text that is not all ASCII\, the byte offset of every 64th scalar value\, its checkpoints\: built in O\(b\) by the first call that needs a position and kept with the value\, so at most once per value\; an ASCII text needs none \(spec\/22 §6\)

## Example

`src/shop.una`

```una
module shop

--- Where the range ends in an SKU. A position counts scalar values, so `É` counts as one.
dash(sku: Text) -> Text
=
  when sku.find(text: "-")
    is Some(at) -> "{sku}: the range ends at {at}"
    is None -> "{sku}: no range"

pub main() -> Unit
  uses @console: Console[print]
=
  @console.print(dash("LAMP-01"))
  @console.print(dash("CAFÉ-01"))
  @console.print(dash("GIFTCARD"))
```

`una run .` prints:

```text
LAMP-01: the range ends at 4
CAFÉ-01: the range ends at 4
GIFTCARD: no range
```

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