Strings

There are two forms of string literals:

  • a string literals with escape sequences support, and
  • a text blocks.

String Literals

A simple string literal starts with a quotation mark (") followed by string content and ends with a closing quotation mark.

A string content may include arbitrary characters excluding new lines.

Escape sequences

To place an arbitrary character, including quotation mark, special characters, and characters from another character set to the string, an escape sequences may be used. The following escape sequences recognized within a string:

Escape sequence Unicode Name Meaning
\t U+0009 CHARACTER TABULATION Tabulation
\n U+000A LINE FEED New line control character
\r U+000D CARRIAGE RETURN CR control character
\" U+0022 QUOTATION MARK " (double quote)
\' U+0027 APOSTROPHE ' (single quote)
\\ U+005C REVERSE SOLIDUS \ (backslash)
\hex_code\ Arbitrary Unicode symbol with code represented in hexadecimal form by hex_code

Text Blocks

A text block fully occupies several lines of source code. It starts an ends with lines containing three or more quotes ("""). Nothing except spaces may appear at the same line.

A text block content may contain new lines and quotation marks and does not recognize any escape sequences.

A trailing spaces of each line are stripped, but the new line character itself is not, except for the very last line.

The following are the same:

"""
line 1
line 2
"""
"line 1\nline 2"

To place a new line character after the last line an additional empty line is required. So, something like this:

"""
first line
last line

"""

will be the same as

"first line\nlast line\n"

Line Continuation

Unlike all other types of expressions, a string is always considered a continuation of the preceding expression. So the following code snippets are equivalent:

Print "Hello, World!" nl
Print
"Hello, World!" nl
Print
_"Hello, World!" nl
Print
"""""""""""""
Hello, World!
"""""""""""""
_nl

String Concatenation

When two or more string literals follow each other they are automatically joined. The following expressions are identical:

"Hello, World!"
"Hello, " "World!"
"""
Hello,
"""
" World!"