substring (Function)

Signature: substring(s: string, start: int, end: int) -> Result<string, Error>

Description: Extracts the byte interval s[start, end), even inside a UTF-8 character. Invalid or inverted bounds return Error.

Parameters

  • s (string): The source string
  • start (int): Starting byte offset (inclusive)
  • end (int): Ending byte offset (exclusive)

Returns: Result<string, Error>

Example

match substring("hello", 1, 4) {
    Success { value } => print(value)
    Error { message } => print(message)
}
match substring ("hello", 1, 4)
    Success value => print value
    Error message => print message