SplitScript reference / String / slice

String.slice

Method

String.slice(start: u32, end: u32) -> String!

Extracts text between two UTF-8 byte offsets.

The start index is inclusive and the end index is exclusive. Invalid, reversed, or out-of-range bounds return an error, as do offsets inside a multibyte code point. The result is newly allocated and can never contain more UTF-8 bytes than this string.

Parameters

  • start: The inclusive UTF-8 byte offset.
  • end: The exclusive UTF-8 byte offset.

Effects: allocates

Runtime behavior: available everywhere; synchronous

Examples

Extract a level-number component

let prefix = "Straße".slice(0, 6) else "Unknown"