Strings


The next type we will look at is the string.

We will review Strings in more detail in the strings chapter, but as a brief introduction string are arrays of bytes, where each byte or group of bytes represents character, which are grouped together to form words or other text-based sequences.

Lua strings are immutable, meaning that they cannot be modified after they are created. Changing a string requires creating a new string that consists of the characters of the previous string, plus whatever changes are desired. We will learn more about this when we look at string buffers and format strings.

Lua strings are defined by sequences of characters contained in:

  1. Double quotes
  2. Single quotes
  3. Double square brackets

The characters of strings defined with either single or double quotes must exist on a single line, while those in strings defined with brackets can be on multiple lines. Strings defined with single and double quotes are equivalent, and both types of quotes are supported so that quote characters can be included in strings themselves.