Character String Literals are used to declare text and character data in a program.
A String Literal is a sequence of characters often used to convey a message. For example:
Example | Comment |
---|---|
'Pressure: 100 mbar' | A message informing us the pressure is 100 mbar. |
'' | An empty string. |
Strings can be single byte or double byte:
Note: Both types of string can encode any Unicode character.
A Character Literal is a single element of a character string. For example:
Example | Comment |
---|---|
'A' | The letter 'A'. |
Characters can be single byte or double byte:
Note: A character can only encode the subset of Unicode characters that fit in a single element. A single byte character (CHAR) can encode any character in the range U+0000 to U+007F. A double byte character (WCHAR) can encode any character in the range U+0000 to U+FFFF.
Single byte strings (STRING) are encoded using UTF-8. Each character is represented by a sequence of 1 to 4 bytes. Double byte strings (WSTRING) are encoded as UTF-16. Each character is represented by 1 or 2 words.
Examples of encoding:
Character | Code Point | STRING Encoding | WSTRING Encoding |
---|---|---|---|
Capital Letter A | U+0041 | 41h | 0041h |
Cyrillic Letter П (Pe) | U+041F | D0h 9Fh | 041Fh |
Chinese character 屋 (house room) | U+5C4B | E5h B1h 8Bh | 5C4Bh |
Linear B Syllable DA | U+10005 | F0h 90h 80h 85h | D800h DC05h |
Use the dollar sign ($) to insert special character codes into a string.
Sequence | Usage | Description |
---|---|---|
$$ | Both | Dollar sign ($) character |
$' | Single | Apostrophe (') character |
$" | Double | Double quotation mark (") character |
$L | Both | Line feed (U+000A) character |
$N | Both | Line feed (U+000A) character |
$R | Both | Carriage return (U+000D) character |
$T | Both | Horizontal tab (U+0009) character |
$nn | Single | Single byte character, where nn is the two digit hexadecimal value of the character |
$nnnn | Double | Double byte character, where nnnn is the four digit hexadecimal value of the character |
Escape sequence characters after the dollar sign ($) are not case sensitive. You can also use $l or $n for line feed (U+000A), and $r for carriage return (U+000D).
Character string literals may be declared with a type prefix:
Prefix | Explanation |
---|---|
CHAR# | Declares a single byte character |
WCHAR# | Declares a double byte character |
STRING# | Declares a single byte string |
WSTRING# | Declares a double byte string |
String | Explanation |
---|---|
'' | An empty single byte string |
"" | An empty double byte string |
'Pressure Normal$r$n' | The message "Pressure Normal" as a single byte string terminated with a carriage return and line feed |
WSTRING#'Pressure Normal$r$n' |
The message "Pressure Normal" as a double byte string terminated with a carriage return and line feed. Note: The apostrophe declares a single byte string, but the WSTRING# prefix overrides it to a double byte string. |
IEC 61131-3 Second Edition: Table 5 & Table 6.
IEC 61131-3 Third Edition: Table 6 & Table 7.
To learn about functions that operate on strings.
To learn about other language Common Elements.
For a list of all Unicode character codes used in IEC 61131-3 code.
For the meaning of terms used in Fernhill SCADA.