- Gets the substring of a string.
- The string.
- The starting index, counting from 1 at the left, or -1 at the right.
- The ending index, counting from 1 at the left, or -1 at the right. (default -1)
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.
Note that negative indices can be very useful. For instance, to get the rightmost four characters of a string, one simply writes
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