Character String Literals

Introduction

Character String Literals are used to declare text and character data in a program.

String Literals

A String Literal is a sequence of characters often used to convey a message. For example:

ExampleComment
'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.

Character Literals

A Character Literal is a single element of a character string. For example:

ExampleComment
'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 into 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.

String Encoding

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:

CharacterCode PointSTRING EncodingWSTRING Encoding
Capital Letter AU+004141h0041h
Cyrillic Letter П (Pe)U+041FD0h 9Fh041Fh
Chinese character 屋 (house room)U+5C4BE5h B1h 8Bh5C4Bh
Linear B Syllable DAU+10000F0h 90h 80h 85hD800h DC05h

Escape Sequences

The dollar sign ($) is used as an escape character to insert any character code into a string.

SequenceUsageDescription
$$BothDollar sign ($) character
$'SingleApostrophe (') character
$"DoubleDouble quotation mark (") character
$LBothLine feed (U+000A) character
$NBothLine feed (U+000A) character
$RBothCarriage return (U+000D) character
$TBothHorizontal tab (U+0009) character
$nnSingleSingle byte character, where nn is the two digit hexadecimal value of the character
$nnnnDoubleDouble 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).

Using Type Prefixes

Character string literals may be declared with a type prefix:

PrefixExplanation
CHAR#Declares a single byte character
WCHAR#Declares a double byte character
STRING#Declares a single byte string
WSTRING#Declares a double byte string

Examples

StringExplanation
''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.

Standards Compliance

Table 5 & 6 - IEC 61131-3 Second Edition.

Table 6 & 7 - IEC 61131-3 Third Edition.

Further Information

String Functions

To learn about functions that operate on strings.

Common Elements

To learn about other language Common Elements.

Character Codes

For a list of all Unicode character codes used in IEC 61131-3 code.

Glossary

For the meaning of terms used in Fernhill SCADA.