str_sub(src, index, len)
Returns a substring of src.
The result is the substring of src
that starts at the byte specified by index with length of at most len
bytes. If the requested substring extends past the end of the original string (i.e. index + len > src length
), the length of the resulting substring is limited to the size of src
.
An exception is thrown in case index
and/or len
are out of bounds. The string is zero-indexed.
Parameters
src:
source string.
index:
integer value specifying the initial byte in the range [0, src length]
len:
(optional) length of the substring in the range [0, MAX_INT]. If len is not specified, the string in the range [index, src length].
Return Value
the portion of src that starts at byte index and spans len characters.
Example command:
str_sub("0123456789abcdefghij", 5, 3)
- returns "567"
str_sub("0123456789abcdefghij", 10)
- returns "abcdefghij"
str_sub("0123456789abcdefghij", 2, 0)
- returns "" (len is 0)
str_sub("abcde", 2, 50)
- returns "cde"
str_sub("abcde", -5, 50)
- error: index is out of bounds