String Literals in Expressions

Use of String Literals

You can use string literals to define fixed strings in expressions. String literals contain double quotation marks at the start and end of the string.

String literals are created within the expression editor with the data type System.String.

The use of special characters in string literals requires special attention in the expression editor. Here are the characters:

Special Characters
Character Description
" Double quotation marks
\ Backslash
cr Carriage return
lf Line feed
crlf Carriage return and line feed
tab Horizontal tab (tab key)

The system setting Allow Verbatim String and Escape Sequences determines how these characters in string literals are interpreted by the expression editor and how the user needs to enter them. You can find this setting in the menu under Start of the navigation pathTools Next navigation step  Options Next navigation step Global Settings Next navigation step CompatibilityEnd of the navigation path. (See also: Compatibility Settings.)

Allow Verbatim String and Escape Sequences

If you have selected the checkbox, the following rules apply in the string literals:

  • Escape sequence

    A combination of a backslash \ and a letter or a number is interpreted as an escape sequence. You can use an escape sequence to define characters that cannot be printed, for example: Carriage return (cr), tab, Unicode characters, or characters reserved in string literals, such as the double quotation mark or the backslash. The expression editor allows the following escape sequences:

    Escape Sequences
    Escape Sequence Resulting Character
    \' Single quotation mark '
    \" Double quotation mark "
    \\ Backslash \
    \a Acoustic signal
    \b Backspace
    \f Form feed
    \n Line feed lf
    \r Carriage return cr
    \t Horizontal tab tab
    \v Vertical tab
    \uxxxx Unicode character with hex value xxxx, for example, \u00AD
    \0 - \9 Unicode characters 0 to 9
  • Verbatim string @

    If you prefix a string literal with the verbatim string @, all characters within the double quotation marks are interpreted literally. This means that backslashes \ are not interpreted as escape sequences either.

    Double quotation marks are an exception: If you want your string to contain double quotation marks, the existing double quotation marks have to be enclosed in additional double quotation marks.

Allow Verbatim String and Escape Sequences Checkbox Not Selected

If you have not selected the checkbox, as in the previous default setting, the following rules apply in string literals:

  • Backslashes \ are not interpreted as escape sequences, but are interpreted literally.

  • To be able to insert the following characters in character strings, you must use special functions of the expression editor and link them to the other parts of the string using the operator &:

    Special Functions in the Expression Editor
    Character PCo Function
    " doublequote
    cr cr
    lf lf
    crlf crlf
    tab tab