String Constants

Overview

A string constant is an arbitrary sequence of characters. STRING constants are preceded and followed by single quotation marks. WSTRING constants are preceded and followed by double quotation marks. The characters are coded according to the character set specified in ISO/IEC 8859-1. You may also enter blank spaces and special characters (special characters for different languages, like accents or umlauts).

If the UTF8 Encoding for STRING option is enabled in the Project Settings > Compile options dialog box, the string literal is interpreted in UTF-8 format (for further information, refer to the Project Settings - Compile Options chapter in the Menu Commands Online Help).

NOTE: A compatibility check is not performed for string literals, so you can enter all characters in the text editor. The compiler, however, compiles unknown characters as ?.

Hexadecimal Code

In strings, the combination of the dollar sign ($) followed by 2 hexadecimal numbers is interpreted as a hexadecimal code according to the coding in ISO/IEC 8859-1. The code corresponds to ASCII code. In addition, note the special cases presented in the table.

Combinations of characters starting with a dollar sign which are interpreted as hexadecimal code:

String with $ code

Interpretation

'$<8-bit code>'

8-bit code: Two-digit hexadecimal number that is interpreted according to ISO/IEC 8859-1.

'$41'

A

'$9A'

©

'$40'

@

'$0D'

Control character: Line break (corresponds to '$R')

'$0A'

Control character: New line (corresponds to '$L' and '$N')

Special Cases of a STRING

Combinations of characters starting with a dollar sign which have a specific meaning:

String with $ code

Interpretation

'$L', '$l'

Control character: Line feed (corresponds to '$0A')

'$N', '$n'

Control character: New line (corresponds to '$0A')

'$P' '$p'

Control character: Form feed

'$R', '$r'

Control character: Line break (corresponds to '$0D')

'$T', '$t'

Control character: Tab

'$$'

Dollar sign $

'$''

Single straight quotation mark: '

Examples

Constant declaration of a STRING:

VAR CONSTANT
    constA : STRING := 'Hello world';
    constB : STRING := 'Hello world $21'; // Hello world!
END_VAR

Examples of WSTRING declarations:

wstr:WSTRING:="This is a WString";
wstr10 : WSTRING(10) := "1234567890";

Constant: UTF8# String

UTF-8-encoded string literals are supported as a single-byte STRING.

Syntax

UTF8#' <string literal> '

Constant declaration

VAR CONSTANT
    constA : STRING := UTF8#'aäoöuü';
    constB : STRING := UTF8#'Hello Allgäu $21'; // Hello Allgäu!
END_VAR
NOTE: To help ensure correct monitoring, add the attribute 'monitoring_encoding' := 'UTF-8'.

For further information, refer to Attribute monitoring_encoding.

Also refer to