Skip to main content

substring

substring(str: String, start: Integer, end: Integer) : String

Returns the substring of string str starting from index start (inclusive) and ending at index end (exclusive).

Examples:

  • substring("abcdef", 0, 6) returns "abcdef"
  • substring("abcdef", 1, 3) returns "bc"
  • substring("abcdef", 1, 1) returns "" (empty string)
Bounds handling

Indices are automatically clamped to valid ranges. The function returns the overlap between the requested range and the available string content, which may be empty if there is no overlap.

Examples:

  • substring("abcdef", -2, 3) returns "abc" (start clamped to 0)
  • substring("abcdef", 2, 10) returns "cdef" (end clamped to length)
  • substring("abcdef", 5, 2) returns "" (no overlap)
  • substring("abcdef", 10, 20) returns "" (no overlap)

See also

Types

Functions