STRING_TO_<type>

This IEC operator converts from the data type STRING to a different data type.

Syntax: STRING_TO_<data type>

You must specify the operand of type STRING in accordance with the IEC 61131-3 standard. The value must be equivalent to a valid constant (literal) of the target data type. This applies to exponential values, infinite values, prefixes, grouping characters ("_") and commas. Additional characters are allowed behind the digits of a number, e.g. 23xy. Additional characters before a number are not permitted.

The operand must represent a valid value of the target data type.

STRING_TO_<type> 1:

If the data type of the operand does not match the destination data type or the value is outside the range of the destination data type, the result output is undefined. Information may be lost during type conversion from larger to smaller data types.

Samples:

ST code

Result

bVar := STRING_TO_BOOL('TRUE');

TRUE

nVar := STRING_TO_WORD('abc34');

0

nVar := STRING_TO_WORD('34abc');

34

tVar := STRING_TO_TIME('T#127ms');

T#127ms

fVar := STRING_TO_REAL('1.234');

1,234

nVar := STRING_TO_BYTE('500');

244

FBD code

Result

STRING_TO_<type> 2:

TRUE

See also: