Basics
45
1.4.1.13 STRING
The data type STRING consists of a series (a string) of up to 32767 ASCII characters. The maximum number of
characters depends on the memory size of the PLC. Change the default setting under Extras Options
Compile options Code generation.
The default initial value, e.g. for variable declarations in the POU header or global variable list, is '', i.e. an empty
string.
Declaration
To declare STRING type variables in the POU header use the following syntax:
STRING[n], where n = number of characters
The default number of characters for STRING is 32.
Internal memory structure of strings on the PLC
Each character of the string is stored in one byte. A string's memory area consists of a header (two words) and
one word for every two characters.
The first word contains the number of characters reserved for the string.
The second word contains the actual number of characters in the string.
Subsequent words contain the ASCII characters (two per word)
To reserve a certain memory area for the string, specify the string length using the following formula: Memory
size = 2 words (header) + (n+1)/2 words (characters)
The memory is organized in word units. Therefore, word numbers are always rounded up to the next whole
number.
Word x Number of characters reserved for string
Word x+1 Actual number of characters in string
Word x+2 Character 2 Character 1
Word x+3 Character 4 Character 3
Word x+4 Character 6 Character 5
... ...
Word x+(n+1)/2+1 Character n Character n-1
High byte Low byte
See F159_MTRN (see page 741) for a programming example.
String literals (according to IEC 61131-3)
A character string literal is a sequence of zero or more characters prefixed and terminated by the single quote
character (').
Three-character combinations of the dollar sign ($) followed by two hexadecimal digits are to be interpreted as
the hexadecimal representation of the eight-bit character code.
Two-character combinations beginning with the dollar sign are to be interpreted as shown in the table:
Combination Interpretation when printed
$$ Dollar sign ($24)
$' Single quote ($27)
$L or $l Line feed ($0A)
$N or $n New line ($0D$0A)
$P or $p Form feed (page) ($0C)
$R or $r Carriage return ($0D)