WSTRING¶
Double-byte (wide) character string with a maximum length.
Size |
Variable (default max 254 characters) |
Default |
|
IEC 61131-3 |
Section 2.3.1 |
Support |
Supported |
Encoding |
UTF-16LE, Basic Multilingual Plane only |
Literals¶
"Hello, world!"
"Double-byte string"
"Say $"hi$""
WSTRING#"typed literal"
"$20AC$L"
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 : WSTRING[50]; (* max 50 characters *)
msg : WSTRING; (* default max length *)
END_VAR
Encoding¶
WSTRING stores UTF-16LE code units. Only the Basic Multilingual Plane is
supported: a code point above U+FFFF has no representation, so surrogate pairs
are not formed. Lengths — the declared maximum, and the value LEN returns —
count code units, not bytes and not user-perceived characters.
The maximum declared length is 65,535 code units.
STRING and WSTRING cannot be mixed. Assigning one to the other, or
comparing or combining them in one operation, is a compile error
(P4034).
The quotes select the type: 'abc' is a STRING literal and "abc" a
WSTRING one, so a literal used with a WSTRING is written with double
quotes:
VAR
w : WSTRING[10] := "abc";
END_VAR
IF w = "abc" THEN
w := CONCAT(w, "d");
END_IF;
A literal written with the wrong quotes is a type mismatch rather than a mixing error, so it is reported as P4035 for an assignment or P4026 for a call argument.
Example¶
unit := WSTRING#"°C";
caption := CONCAT(WSTRING#"Kiln temperature ", unit);
caption_len := LEN(caption); (* caption_len = 19 *)
caption holds 19 code units and occupies 38 bytes. IronPLC displays a wide
value as a double-quoted literal and escapes every code unit outside printable
ASCII, so caption reads back as "Kiln temperature $00B0C" — ° is the
single code unit $00B0.