substr
lib callCapy
function substr(value : string, start : s32) string function substr(value : string, start : s64) string function substr(value : string, start : s32, length : s32) string function substr(value : string, start : s64, length : s64) string
Description
substr selects bytes without changing the source. Positions and lengths count bytes, not Unicode characters.
A negative start counts from the end. A start before the beginning clamps to zero. A start at or beyond the end returns an empty string.
A nonnegative length selects at most the remaining bytes. A negative length excludes that many bytes from the end. An empty or reversed range returns an empty string. Without a length, the result includes all remaining bytes.
These rules also apply to the minimum and maximum signed indices. Large lengths clamp to the remaining bytes before addition, so extreme inputs do not overflow or trap. NUL and non-UTF-8 bytes remain unchanged.
Return Values
Extracted text.
Example
Capy
print(substr("documentation", 0, 3), "\n")
Output
doc