Home / Docs / Standard library / Prelude

contains_text

Release v0.4.0Edition 0.2 and later

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

una
pub contains_text(t: Text, part: Text) -> Bool

Whether part occurs in t (spec/22 §2).

Parameters

Returns

Bool: true when part occurs in t.

Use instead

See also

starts_with, ends_with

Cost

Time O(b + m) (ADR 0070), where:

Example

src/shop.unauna
module shop

--- Whether a product description names a finish.
pub main() -> Unit
  uses @console: Console[print]
=
  let brass = "Desk lamp, brass".contains_text(part: "brass")
  @console.print("brass: {brass}")
  let steel = "Desk lamp, brass".contains_text(part: "steel")
  @console.print("steel: {steel}")

una run . prints:

Output
brass: true
steel: false

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.