LANGUAGE ยป LUA

String

String โ€‹

lua
name = "Hime"
concatenate = "Hello " .. "World"

Functions โ€‹

The g in some functions stands for global.

FunctionDescription
formatFormat a string using the same rules as sprintf.
subReturn a substring from start index to end. Negative values count from behind.
gsubPerform replace using a regex pattern.
matchReturn a match using a regex pattern.
gmatchReturn all matches using a regex pattern (^ at the beginning doesn't work).
lenReturn the length of the string.
lowerReturn a copy of the string in lowercase.
upperReturn a copy of the string in uppercase.

Examples โ€‹

Format a string:

lua
formatting = string.format("Hello %s!", name)

Remove last character:

lua
string.sub(my_str, 1, -2)