API Reference › Text › Text.starts_with
method

Text.starts_with

Text.starts_with(s, prefix) -> bool

Returns true when s begins with prefix, comparing byte for byte over the length of the prefix. An empty prefix always matches. Use it to route commands ("/help ..."), recognize a tag, or branch on a filename extension without slicing first.

Parameters

sthe string to test
prefixthe leading substring to look for

Example

program Command {
  var input: string = "/say hello"

  handler Parse phase Update {
    if Text.starts_with(input, "/say ") {
      let msg = Text.slice(input, 5, Text.length(input))
    }
  }
}
← All symbols