Lua string functions

Lua string functions

These are the functions in the "string" table.

Indices, where used, start at 1 for the first character (not zero). Negative numbers count from the right, so -1 is the last character, -2 the second last, and so on.

All strings have a metatable added to them by Lua with an __index entry pointing to the string table. What this means is that you can write string function calls in two ways:

s = "hello, world"
string.len (s) --> 12
s:len ()       --> 12
The second version is shorter as the word "string" is implied. Note the colon after the s, not a dot.

Lua functions

Topics