String (UTF-8 binary) operations: length, concat, split, trim, case conversion, and integer/float/atom parsing.

String is Erlang's binary type. length/1 reports the byte size; case conversion and trimming go through OTP's Unicode-aware :string module. Numeric parsers raise on malformed input, matching the underlying BIFs.

Examples

use Std.String

length("hello")                         # => 5
concat("foo", "bar")                    # => "foobar"
upcase("cafe")                          # => "CAFE"
split("a,b,c", ",")                     # => ["a", "b", "c"]
repeat("ab", 3)                         # => "ababab"
use Std.String

from_int(42)                            # => "42"
to_int("  -17 " |> trim)                # => -17

Functions

  • # fn __group__() -> Atom

    Group tag consumed by Cure.Stdlib.Preload.

  • # fn concat(a: String, b: String) -> String

    Concatenate two strings; uses the <> binary operator.

  • # fn downcase(s: String) -> String extern

    Lower-case s using Unicode case folding (:string.lowercase/1).

  • # fn from_atom(a: Atom) -> String extern

    Render an Atom as its name; no : prefix is added.

  • # fn from_float(f: Float) -> String extern

    Render a Float as its canonical decimal string.

  • # fn from_int(n: Int) -> String extern

    Render an Int as its canonical decimal string.

  • # fn is_empty(s: String) -> Bool

    true when s is the empty string.

  • # fn length(s: String) -> Int extern

    Byte length of s; delegates to :erlang.byte_size/1. This is not grapheme count: multi-byte code points contribute more than one.

  • # fn repeat(s: String, n: Int) -> String extern

    Return s concatenated with itself n times (:binary.copy/2).

  • # fn reverse(s: String) -> String

    Reverse s. Operates on the underlying charlist, so the result is byte-reversed rather than grapheme-reversed.

  • # fn split(s: String, sep: String) -> List(String) extern

    Split s on every occurrence of sep. Uses :binary.split/2.

  • # fn to_atom(s: String) -> Atom extern

    Convert s to an atom. Raises on bad encoding; beware atom-table exhaustion in long-running nodes if s is attacker-controlled.

  • # fn to_float(s: String) -> Float extern

    Parse s as a float. Raises on bad input.

  • # fn to_int(s: String) -> Int extern

    Parse s as a base-10 integer. Raises on bad input.

  • # fn trim(s: String) -> String extern

    Strip leading and trailing whitespace (:string.trim/1).

  • # fn trim_leading(s: String) -> String extern

    Strip leading whitespace only.

  • # fn trim_trailing(s: String) -> String extern

    Strip trailing whitespace only.

  • # fn upcase(s: String) -> String extern

    Upper-case s using Unicode case folding (:string.uppercase/1).