Some characters cannot be included in [[literal_string?]]s, because they are [[nonprintable?]] or [[control_character?]]s, or characters that affect [[delimit?]]ation of the strings, such as [[quotation_mark?]]s. These characters can be inserted by using an *escape sequence* (known as *literal character notation*).
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.
Escape sequences can be used to represent [[nonprintable?]] and [[control_character?]]s, 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
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 [[delimit?]]ed using an alternative delimiter.
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.";
The following literal character representations are available by using the backslash symbol:
\a | bell |
\b | backspace |
\e | escape |
\f | formfeed |
\n | newline |
\r | carriage return |
\t | tab |
\v | vertical tab |
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 |
[[ASCII?]]
[[Unicode?]]