STRING_TO Conversions

Definition

IEC operator for conversions from the variable type STRING to a different type.

Syntax

STRING_TO_<data type>

Specifying Values

Specify the operand of type STRING matching the IEC61131-3 standard. The value must correspond to a valid constant (literal) of the target type. This applies to the specification of exponential values, infinite values, prefixes, grouping character ("_") and comma. Additional characters after the digits of a number are allowed, as for example, 23xy. Characters preceding a number are not allowed.

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

NOTE: If the data type of the operand does not match the target type, or if the value exceeds the range of the target data type, then the result depends on the processor type and is therefore undefined.

Conversions from larger types to smaller types may result in loss of information.

Caution_Color.gifCAUTION

LOSS OF DATA

When converting mismatched data types or when the value being converted is larger than the target data type, be sure that the result is validated within your application.

Failure to follow these instructions can result in injury or equipment damage.

Example in IL

Example

Conversion result

LD 'TRUE'
STRING_TO_BOOL
ST b

TRUE

Examples in ST

Example

Conversion 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

Example in FBD

Example

Conversion result

G-SE-0024437.1.gif-high.gif

 

 

TRUE