Lua Programming/How to Lua/length operator
From Wikibooks, open books for an open world
Length operator [edit]
The hash symbol can be used as a length operator for obtaining the length of a string or table.
Length of a string [edit]
print (#"oranges") -- 7
Note that in lua, the string library provides a string.len function, which can also be used to determine the length of a string:
print (string.len("oranges")) -- 7
Length of a table [edit]
For a regular array with numerical indices, the length operator returns the number of the last populated element. However, if the array contains a nil value, this may be interpreted as the end of the array by the length operator:
This page may need to be