Skip to content

@lang:str.slice

Extract a UTF-8 byte range, with clamped indexes and complete characters.

On-chain (@lang:str.slice!): Slices UTF-8 bytes; ranges cutting through a character are rejected.

Returns: string

@lang:str.slice(value start end?)
NameTypeDescription
valuestringSource string or bytes value
startnumberStart index (inclusive; negative counts from the end)
[end]numberEnd index (exclusive; negative counts from the end; omitted = to the end)

Both modes use UTF-8 byte offsets, an inclusive start and an exclusive end. Negative indexes count from the end; bounds clamp to the byte length, and reversed ranges produce an empty string. Nonempty ranges must contain complete UTF-8 characters. Runtime source and indexes are resolved at execution time. Use @bytes.slice for arbitrary byte ranges.