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 |
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: Two-digit hexadecimal number that is interpreted according to ISO/IEC 8859-1 |
|
|
|
|
|
|
|
|
|
|
|
Control character: Line break (corresponds to '$R') |
|
|
Control character: New line (corresponds to '$L' and '$N') |
Table 19. Special cases
|
String with $ code |
Interpretation |
|---|---|
|
|
Control character: Line feed (corresponds to |
|
|
Control character: New line (corresponds to |
|
|
Control character: Form feed |
|
|
Control character: Line break (corresponds to |
|
|
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