Lua Programming/How to Lua/interpolation

Variable namesEdit

There is no default support for automatic interpolation of variables names being used as placeholders within a string. However, interpolation can be emulated by using the [string.gsub] function:

mystring = string.gsub("Mary had a X lamb.", "X", "little")
print mystring

Literal charactersEdit

Interpolation of literal character escape sequences does occur within a string:

print "Mary had a \n lamb"    -- The \n is interpreted as an escape sequence for a newline

Bold text

Last modified on 22 February 2013, at 16:08