WSTRING

According to the IEC 61131-3 standard, the data type WSTRING follows the UCS-2 coding.

The character string is identified as WSTRING with double quotation marks. It is optional to specify the size and initialization. If no size is specified, 80 characters (WORD) are reserved by default. There is also a WORD for the final zero.

If a variable of the data type WSTRING is reinitialized by a reset of the application, the byte pairs of the (old) string present after the final zero word (WORD) of the initial value are not overwritten. This applies both to initialization with the initialization value and to initialization with the default initialization value 0.

UCS-2

The UCS-2 encoding includes an extended character set compared to the Latin-1 encoding, but it is still smaller than the UTF-8 encoding. See also the description of the data type STRING.

UCS-2 encoding means that a character is encoded exactly with the fixed length of 2 bytes. UCS-2 includes the characters of the code points from U+0000 to U+D7FF and from U+E000 to U+FFFF.
The string is terminated with 0.

WSTRING 1:

The data type WSTRING requires 1 WORD per character and 1 WORD extra for the final 0. This results in 162 bytes in the case of a standard WSTRING(80) declaration, for example.

Sample:

wsVar : WSTRING := "This is a WString.";

See also: