Lua Basics

Strings

In Lua, a string is any collection of characters. It can be enclosed in single quote characters, double quote characters, or pairs of square brackets:

"Dr. John Smith"
'Radiology'
[[Downtown Hospital]]

You can use square brackets to enclose multiple lines:

[[The results of the lab tests are in.
No abnormalities have been detected.]]

If you want to include brackets in a multi-line string, you can use an open bracket [ followed by one or more = characters and then another open bracket to indicate the start of a string. The string is ended by a close bracket ], the same number of = characters, and another close bracket:

[==[This string contains [] bracket
characters, but is ended by a ], two = and another ].]==]

[=[This string also contains [] brackets]=]

Lua uses the ‘..’ operator to join strings. There is also a library for standard string manipulation, like finding and extracting substrings, and pattern matching.

For more about strings see: the Values and Types in the Lua reference manual, strings in the online programming book and the Lua Tutorial wiki.

For more about string concatenation see: the Concatenation section in the Lua reference manual, the online programming book also concatenation is covered in the strings tutorial of the Lua Tutorial wiki.

For more about the string library see: the string library section in the Lua reference manual, the online programming book and the Lua Tutorial wiki.

Tagged: