# Lua Programming/How to Lua/escape sequence

Some characters cannot be included in literal strings, because they are nonprintable or control characters, or characters that affect delimitation of the strings, such as quotation marks. These characters can be inserted by using an *escape sequence* (known as *literal character notation*).

## The backslash symbol can be used to insert literal characters into a string

An *escape sequence* consists of a backslash symbol followed by a character or set of characters used to represent the literal character using a representation encoding.

## Representation of nonprintable and control characters

Escape sequences can be used to represent nonprintable and control characters, such as tab or newline characters. The example shows a newline character being represented by an escape sequence in the middle of a literal string:

print "first line \n second line"    -- The \n represents a newline character in a string

The above produces the following output:

first line
second line

## Representation of doublequote marks

The doublequote symbol is used to delimit the beginning or end of a string. This means that a doublequote could not be used within the string, unless it is escaped by using a backslash prefix, or the string is delimited using an alternative delimiter.

print('"test"')

## Representation of the backslash symbol

The backslash symbol is another character that cannot be included in an interpolated string. This is because the backslash symbol is used to mark the beginning of an escape sequence. In order to represent the backslash symbol it is necessary to use a doublebackslash within the string:

print "There is only one slash (\\) printed here.";

## Literal character representation

The following literal character representations are made available by using the backslash symbol:

| \" | doublequote | \' | apostrophe | \\ | backslash | \[ | left box enclosure | \] | right box enclosure | \a | bell | \b | backspace | \e | escape | \f | formfeed | \n | newline | \t | horizontal tab | \r | carriage return | \t | tab | \v | vertical tab

## Literal characters can be represented by using their ASCII numeric codes

In Lua, literal characters can be inserted into strings by using their ASCII numeric codes in the following notation:

| \ddd | dd is an octal value | \xhh | hh is a hexadecimal value