Operator ‘STRING_TO’

This IEC operator is used for converting the STRING data type into another data type.

STRING_TO_<data type>

You must define the STRING operand according to the IEC 61131-3 standard. The value has to be a valid constant (literal) of the target type. This affects any given exponential values, infinite values, prefixes, grouping characters (_), and commas. Additional characters after the digits of a number are permitted (for example, 23xy). Additional characters before a number are not permitted.

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

Attention

If the data type of the operand does not match the target data type or if the value is outside the range of the target data type, then the result output depends on the processor type and is therefore undefined. Information can be lost when converting from larger data types to smaller data types.

Examples

ST Code Result
b := STRING_TO_BOOL('TRUE'); TRUE
w := STRING_TO_WORD('abc34'); 0
w := STRING_TO_WORD('34abc'); 34
t := STRING_TO_TIME('T#127ms'); T#127ms
r := STRING_TO_REAL('1.234'); 1.234
bv := STRING_TO_BYTE('500'); 244
FBD Code Result
../_images/04f2fe1abc6e9fe3c0a8640e016f4abc TRUE