== STRING type variables == {{anchor:string}} **STRING** also has two subtypes, just like [[char_type_variables|CHAR]]. The old, //"old-school"// STRING, which describes the text with ASCII characters, and WSTRING, which uses WCHAR characters with two bytes per character. Both types are suitable for storing text, which can be extremely useful for communication, especially in HMI connections. For both types, the first two positions show the maximum length of the given STRING and the current length it has been filled with. One position equals one byte for STRING, and one word for WSTRING. {{:automation:string_example_1.png|STRING type variables 1st examples}} In the example above, taken from the PLC status, I entered the phrase “lama!” into an 8-byte STRING variable. The first two bytes contain the maximum length of the STRING (8) and the current length (5), followed by the phrase as our message. If I change the display format to hexadecimal for the characters, I see the ASCII code for each letter. {{:automation:string_example_2.png|STRING type variables 2nd examples}} That is, the letter “l” is ASCII 16#6C, and "a” is ASCII 16#61, ... {{anchor:wstring}} For **WSTRING**, this assignment appears like this: {{:automation:string_example_3.png|STRING type variables 3rd examples}} The //“$00l”// content type is due to the nature of UNICODE, as //“simple”// characters do not fill the entire UCS-2 space. It is clear that while we counted the positions per byte above, in this case each position occupies a word. The first two words here also contain the maximum length of the STRING (8) and the current length (5). The same definition is given in hexadecimal form as follows: {{:automation:string_example_4.png|STRING type variables fourth examples}} If we fully fill in the UCS-2 word field, we can see what the //“non-simple characters”// look like. In the first step, I entered longer codes in the word variables per character (1), and from this the “example” WSTRING (2) was displayed: {{:automation:string_example_5.png|STRING type variables fifth examples}} To sum it all up: ^Type^Length^Character encoding^Length (characters)^Example| |**STRING**|2 byte + text|CHAR, ASCII|0 .. 254 byte / character|'lamaPLC', STRING#'lamaPLC'| |**WSTRING**|2 word + text|WCHAR, UNICODE|0 .. 16382 word / character|WSTRING#lamaPLC| More information: TIA Datatypes: [[#tia_types|S7 data types summary table]] \\