import { Aside } from ‘@astrojs/starlight/components’;
std.strings provides byte-oriented operations on string values: searching, trimming, case
conversion, replacement, splitting and joining. It is the text-layer counterpart to
std.bytes , which provides the same API over mutable []byte.
All operations treat strings as sequences of bytes, not runes. Case conversion (`to_upper`,
`to_lower`) and whitespace detection (`trim_space`) handle ASCII only; Unicode-aware
variants will live in a future `std.unicode` module.
Every function that produces a string allocates a fresh buffer — Sysl strings are immutable
and there is no zero-copy substring view today. Operations that don’t change the string (like
contains) don’t allocate.
Function Signature Behaviour has_prefix(s, prefix)(string, string) -> boolEmpty string is a prefix of every string has_suffix(s, suffix)(string, string) -> boolEmpty string is a suffix of every string index(s, sub)(string, string) -> intByte offset of first occurrence, or -1 last_index(s, sub)(string, string) -> intByte offset of last occurrence, or -1 contains(s, sub)(string, string) -> boolConvenience around index >= 0 count(s, sub)(string, string) -> intNon-overlapping occurrences; empty sub returns len(s) + 1 (Go parity) index_byte(s, b)(string, byte) -> intFirst byte offset where s[i] == b last_index_byte(s, b)(string, byte) -> intLast byte offset where s[i] == b
Function Signature Behaviour substring(s, start, end)(string, int, int) -> stringHalf-open range [start, end), traps on out-of-bounds
Function Signature Behaviour trim_space(s)(string) -> stringStrip ASCII whitespace from both ends trim_left(s, cutset)(string, string) -> stringStrip any leading byte that appears in cutset trim_right(s, cutset)(string, string) -> stringStrip any trailing byte that appears in cutset trim(s, cutset)(string, string) -> stringtrim_left then trim_right
Function Signature to_upper(s)(string) -> stringto_lower(s)(string) -> string
Function Signature Behaviour replace_all(s, old, new)(string, string, string) -> stringEvery non-overlapping occurrence repeat(s, count)(string, int) -> stringTraps on negative count
Function Signature Behaviour split(s, sep)(string, string) -> []stringSplits on every occurrence of sep fields(s)(string) -> []stringSplits on runs of ASCII whitespace join(xs, sep)([]string, string) -> stringJoins slice with sep between elements
val line = " user=alice role=admin "
val kvs = fields ( trim_space (line))
val eq = index_byte (kv, '=' )
val k = substring (kv, 0 , eq)
val v = substring (kv, eq + 1 , len (kv))
Output:
std.builder — growable string builder used to assemble
result strings inside the module.
std.strconv — parse integers, format numbers, quote
strings.
std.regex — when you need real pattern matching instead of substring
search.