FANDOM


sub( str, start, [end] )
Gets the substring of a string.
str
The string.

start
The starting index, counting from 1 at the left, or -1 at the right.

end
The ending index, counting from 1 at the left, or -1 at the right. (default -1)

The start and end indices are inclusive, which is to say the characters at both indices will be included in the result. To extract a single character, use the same value for both, e.g. sub(s,i,i).

Note that negative indices can be very useful. For instance, to get the rightmost four characters of a string, one simply writes sub(s,-4).

Examples Edit

print(sub("hello there", 1, 5))    -- hello
print(sub("hello there", -5))      -- there

PICO-8 now has a built-in way to associate characters with numbers. You can use Chr to convert an ordinal (0-255) to It's string counterpart.

Converting a character back to a number is just as simple. You can use Ord to get the ordinal value of a character

See also Edit

Community content is available under CC-BY-SA unless otherwise noted.