String Constants¶
A string constant is a character 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.
Example: 'Hello world!'
When a dollar sign ($) is in a string constant, 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, please note the special cases.
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’) |
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
Constant declaration
VAR CONSTANT
\ constA : STRING := 'Hello world';
\ constB : STRING := 'Hello world $21'; // Hello world!
END_VAR