Skip to main content

String Constants

A string constant is a string enclosed in single straight quotation marks. The characters are coded according to the character set specified in ISO/IEC 8859-1. Therefore, a string constant can include spaces and accented characters, as these belong to this character set. This is also referred to as a string literal, or simply a string.

However, when the UTF-8 Encoding for STRING compile option is enabled, the string literal is interpreted in UTF-8 format. This encoding is compatible with ASCII as well as Latin-1. Therefore, the hexadecimal codes and the control-character special cases are also valid in UTF-8.

Example: 'Hello world!'

Note

String literals are not checked for compatibility. As a result, the text editor allows the input of all characters. However, the compiler compiles unknown characters with ?.

Hexadecimal code

When a dollar sign ($) is in a string literal, the following two characters are interpreted as a hexadecimal code according to the coding in ISO/IEC 8859-1. The code also corresponds to ASCII code. In addition, note the special cases and control characters.

Table 18. 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

'$A9'

©

'$40'

@

'$0D'

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

'$0A'

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



Table 19. Special cases

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: '



Example 182. Constant declaration
VAR CONSTANT
        constA : STRING := 'Hello Allgäu';
        constB : STRING := 'Hello Allgäu $21'; // Hello Allgaeu!
END_VAR