String Overview

A string is zero or more characters put together. A character is anything that you can type, such as a letter, a digit, a symbol, or a space. Strings are used to hold any kind of text information.

String literals

A string literal consists of zero or more characters enclosed in double quotes. Each character may be represented by an escape sequence. The following are examples of string literals:
// empty string
display ""

// a string containing 16 characters
display "This is a string."

// a string containing one double quote
display "\\""
In PBL style, consecutive strings are automatically merged:
display "This is a string "
        "made from separate strings."

The above code displays:

This is a string made from separate strings.

Escape sequences

Character and string escape sequences are used to denote some special characters as well as the single quote, double quote, and backslash characters in string literals. The following table lists the most common characters:
Escape code Unicode Description
\t 0009 Horizontal tab (HT)
\n 000a Newline or line feed (LF)
\f 000c Form feed (FF)
\r 000d Carriage return (CR)
\' 0027 Single quote
\" 0022 Double quote
\\ 005c Backslash

If you know the Unicode code, any character can be specified. You must prefix the four-digit hexadecimal code of the desired character with "\u". For example, the double quote would be expressed as "\u0022".

String concatenation

Strings can be concatenated at runtime with the string concatenation operator '+'. You can use any data type to build a string, so long as at least one of the elements is a string:
total as Int
total = 200
display "Total is: " + total + " units"

Regular Expressions

Advanced string pattern matching and manipulation can be done with regular expressions. For further information, please see Regular Expressions.