STRING¶
Single-byte character string with a maximum length.
Size |
Variable (default max 254 characters) |
Default |
|
IEC 61131-3 |
Section 2.3.1 |
Support |
Supported |
Literals¶
'Hello, world!'
'It$'s escaped'
STRING#'typed literal'
'$41$42 costs $$5'
A $ inside a literal starts an escape. Each escape is one character of
the string:
Escape |
Character |
|---|---|
|
Dollar sign |
|
Single quote |
|
Double quote |
|
Line feed |
|
Carriage return |
|
Form feed |
|
Tab |
|
The character with that code, for example |
|
The character with that code, for example |
The letters may be lower case. Any other escape is error P0012.
The maximum length can be specified in the declaration:
VAR
name : STRING[50]; (* max 50 characters *)
msg : STRING; (* default max length *)
END_VAR
Example¶
name := 'my name';
msg := 'a message';
Constant Length (Language Extension)¶
Note
This is an extension not part of the IEC 61131-3 standard. See Enabling Dialects and Features for how to enable it.
With the --allow-constant-type-params flag, you can
use a global constant for the maximum length instead of a literal:
VAR_GLOBAL CONSTANT
MAX_NAME_LEN : INT := 50;
END_VAR
FUNCTION_BLOCK fb1
VAR_EXTERNAL CONSTANT
MAX_NAME_LEN : INT;
END_VAR
VAR
name : STRING[MAX_NAME_LEN];
END_VAR
END_FUNCTION_BLOCK