Introduction
Data types in character string format belong to the EDT (Elementary data type) family, which includes single rather than derived data types (tables, structures, function blocks).
The Character String Type
The character string format is used to represent a string of ASCII characters, with each character being coded in an 8 bit format.
The characteristics of character string types are as follows:
16 characters by default in a string (excluding end of string characters)
a string is composed of ASCII characters between 16#20 and 16#FF (hexadecimal representation)
in an empty string, the end of string character (code ASCII "ZERO") is the first character of the string
the maximum size of a string is 65535 characters
The size of the character string can be optimized during the definition of the type using the STRING[<size>] command, <size> being an unsigned integer UINT capable of defining a string of between 1 and 65535 ASCII characters.
Syntax Rules
The entry is preceded by and ends with the quote character "’" (ASCII code 16#27).
The $ (dollar) sign is a special character, followed by certain letters which indicate:
$L or $l, go to the next line (line feed)
$N or $n, go to the start of the next line (new line)
$P or $p, go to the next page
$R or $r, carriage return
$T or $t tabulation (Tab)
$$, represents the character $ in a string
$’, represents the quote character in a string
The user can use the syntax $nn to display, in a STRING variable, caracters which must not be printed. It can be a carriage return (ASCII code 16#0D) for instance.
Examples
Entry examples:
Type |
Entry |
Contents of the string • represents the end of string character * represents empty bytes |
---|---|---|
STRING |
‘ABCD’ |
ABCD•************ (16 characters) |
STRING[4] |
‘john’ |
john• |
STRING[10] |
‘It$’s john’ |
It’s john•* |
STRING[5] |
’’ |
•***** |
STRING[5] |
’$’’ |
’•**** |
STRING[5] |
‘the number’ |
the no• |
STRING[13] |
’0123456789’ |
0123456789•*** |
STRING[5] |
‘$R$L’ |
<cr><lf>•*** |
STRING[5] |
’$$1.00’ |
$1.00• |
STRING Type Variable Declaration
A STRING type variable can be declared in two different ways:
STRING and
STRING[<Number of elements>]
Behavior differs depending on usage:
Type |
Variable declaration |
FFB input parameter |
EF output parameter |
FB output parameter |
---|---|---|---|---|
STRING |
Fixed size: 16 characters |
The size is equal to the actual size of the input parameter. |
The size is equal to the actual size of the input parameter. |
Fixed size of 16 characters |
STRING[<n>] |
Fixed size: n characters |
The size is equal to the actual size of the input parameter limited to n characters. |
The EF writes a maximum of n characters. |
The FB writes a maximum of n characters. |
Strings and the ANY Pin
When you use a STRING type variable as an ANY type parameter, it is highly recommended to check that the size of the variable is less than the maximum declared size.
Example:
Use of STRING on the SEL function (Selector).
String1: STRING[8]
String2: STRING[4]
String3: STRING[4]
String1:= 'AAAAAAAA';
String3:= 'CC';
Scenario 1:
String2:= 'BBBB';
(* the size of the string is equal to the maximum declared size *)
String1:= SEL(FALSE, String2, String3);
(* the result will be: 'BBBBAAAA' *)
Scenario 2:
String2:= 'BBB';
(* the size of the string is less than the maximum declared size *)
String1:= SEL(FALSE, String2, String3);
(* the result will be: 'BBB' *)