



NOTICE

If the operand value for a type conversion operator is outside of the value range
of the target data type, then the result output depends on the processor type and
is therefore undefined. This is the case, for example, when a negative operand value
is converted from LREAL
to the target data type UINT
.
Information can be lost when converting from larger data types to smaller data types.
The operators convert a character string (STRING
or WSTRING
) into the specified target data type and return a type-converted value.
A conversion with a meaningful result is only possible when the operand matches the target data type according to the IEC 61131-3 standard. This is the case if the value of the operand corresponds to a valid constant (literal) of the target data type.
Convertible strings contain:
-
Number with type prefix (example:
'16#FFFFFFFF'
) -
Number with grouping characters (example:
'2#1111_1111'
)Note: The international weight and measure grouping character (thin space) is not accepted. Only the underscore is accepted.
-
Floating-point number, also in exponential notation (example:
'9.876'
or'1.2E-34'
)Note: Floating-point numbers are not convertible. The comma is treated and truncated like a following character.
-
Time, time of day, and date specification with prefix and size (example:
'T#2h'
,'DT#2019-9-9-12:30:30.9'
) -
Infinite values (example:
'1.7E+400'
) -
Additional character after a number (example:
'2m'
or'3.14'
). These are truncated. Additional characters before a number are not permitted. -
Spaces before (example:
' 3.14'
)
Call syntax
<variable name> := <string to operator> ( <operand> ); <operand> = <variable name> | <literal>
Operators
STRING_TO___UXINT STRING_TO___XINT STRING_TO___XWORD STRING_TO_BIT STRING_TO_BOOL STRING_TO_BYTE STRING_TO_DATE STRING_TO_DINT STRING_TO_DT STRING_TO_DWORD STRING_TO_INT STRING_TO_LDATE STRING_TO_LDT STRING_TO_LINT STRING_TO_LREAL STRING_TO_LTIME STRING_TO_LWORD STRING_TO_LTIME STRING_TO_LTOD STRING_TO_REAL STRING_TO_SINT STRING_TO_TIME STRING_TO_TOD STRING_TO_UDINT STRING_TO_UINT STRING_TO_ULINT STRING_TO_USINT STRING_TO_WORD STRING_TO_WSTRING WSTRING_TO___UXINT WSTRING_TO___XINT WSTRING_TO___XWORD WSTRING_TO_BIT WSTRING_TO_BOOL WSTRING_TO_BYTE WSTRING_TO_DATE WSTRING_TO_DINT WSTRING_TO_DT WSTRING_TO_DWORD WSTRING_TO_INT WSTRING_TO_LDATE WSTRING_TO_LDT WSTRING_TO_LINT WSTRING_TO_LREAL WSTRING_TO_LTIME WSTRING_TO_LTOD WSTRING_TO_LWORD WSTRING_TO_LTIME WSTRING_TO_REAL WSTRING_TO_SINT WSTRING_TO_STRING WSTRING_TO_TIME WSTRING_TO_TOD WSTRING_TO_UDINT WSTRING_TO_UINT WSTRING_TO_ULINT WSTRING_TO_USINT WSTRING_TO_STRING WSTRING_TO_WORD
Converting to a Boolean value
Operator STRING_TO_BOOL
: A value of TRUE
is returned only if the operand value is 'TRUE'
or 'true'
. On the other hand, FALSE
is returned for 'True'
.
Operator WSTRING_TO_BOOL
: A value of TRUE
is returned only if the operand value is "TRUE"
or "true"
. On the other hand, FALSE
is returned for "True"
.

Examples
ST implementation language
FUNCTION_BLOCK FB_ConvertStrings VAR_INPUT END_VAR VAR_OUTPUT END_VAR VAR xReturn_0: BOOL; xReturn_1: BOOL; dateReturn: DATE; dtReturn: DATE_AND_TIME; iReturn: INT; lrReturn: LREAL; lrReturn_0: LREAL; lwReturn: LWORD; lwReturn_0: LWORD; lwReturn_1: LWORD; ltReturn: LTIME; ltReturn_0: LTIME; ltReturn_1: LTIME; ltReturn_2: LTIME; rReturn: REAL; rReturn_0: REAL; timReturn: TIME; timReturn0: TIME; timReturn1: TIME; timReturn2: TIME; todReturn: TIME_OF_DAY; todReturn0: TIME_OF_DAY; todReturn1: TIME_OF_DAY; todReturn2: TIME_OF_DAY; uliReurn: ULINT; uliReurn_0: ULINT; uliReurn_1: ULINT; wReturn: WORD; wReturn_0: WORD; wReturn_1: WORD; wstrReturn: WSTRING; wstrReturn_0: WSTRING; END_VAR xReturn_0 := STRING_TO_BOOL('FALSE'); xReturn_1 := STRING_TO_BOOL('TRUE'); dateReturn := STRING_TO_DATE('DATE#2019-9-9'); dtReturn := STRING_TO_DT('DT#2019-9-9-1:1:1.1'); iReturn := STRING_TO_INT('123abc'); lrReturn := STRING_TO_LREAL('4.94E-323'); lrReturn_0 := STRING_TO_LREAL('1.7E+308'); lwReturn := STRING_TO_LWORD('16#FFFF_FFFF_FFFF_FFFF'); lwReturn_0 := STRING_TO_LWORD('16#0123456789ABCDEF'); lwReturn_1 := STRING_TO_LWORD('16#0123456789ABCDEF'); ltReturn := STRING_TO_LTIME('LTIME#213503d23h34m33s709ms551us615ns'); ltReturn_0 := STRING_TO_LTIME('LTIME#0ns'); ltReturn_1 := STRING_TO_LTIME('LTIME#1ms'); ltReturn_2 := STRING_TO_LTIME('LTIME#2s'); rReturn := STRING_TO_REAL('6.543e21'); rReturn_0 := STRING_TO_REAL('1.234'); timReturn := STRING_TO_TIME('T#5d4h3m2s'); timReturn0 := STRING_TO_TIME('TIME#1s'); timReturn1 := STRING_TO_TIME('1s'); timReturn2 := STRING_TO_TIME('TIME#5s'); todReturn := STRING_TO_TOD('TOD#12:0:0.1'); todReturn0 := STRING_TO_TOD('TOD#0:0:0.0'); todReturn1 := STRING_TO_TOD('20:15'); todReturn2 := STRING_TO_TOD('TOD#20:15'); uliReurn := STRING_TO_ULINT('18446744073709551615'); uliReurn_0 := STRING_TO_ULINT('1'); uliReurn_1 := STRING_TO_ULINT('0'); wReturn := STRING_TO_WORD('16#FFFF_0000'); wReturn_0 := STRING_TO_WORD('34abc'); wReturn_1 := STRING_TO_WORD('16#34abc'); wstrReturn := STRING_TO_WSTRING('Hello World!'); wstrReturn_0 := STRING_TO_WSTRING('123456789');

WSTRING
conversion in ST
FUNCTION_BLOCK FB_ConvertWstrings VAR xReturn_0: BOOL; xReturn_1: BOOL; dateReturn: DATE; dtReturn: DATE_AND_TIME; iReturn: INT; lrReturn: LREAL; lrReturn_0: LREAL; lwReturn: LWORD; lwReturn_0: LWORD; lwReturn_1: LWORD; ltReturn: LTIME; ltReturn_0: LTIME; ltReturn_1: LTIME; ltReturn_2: LTIME; rReturn: REAL; rReturn_0: REAL; timReturn: TIME; timReturn0: TIME; timReturn1: TIME; timReturn2: TIME; todReturn: TIME_OF_DAY; todReturn0: TIME_OF_DAY; todReturn1: TIME_OF_DAY; todReturn2: TIME_OF_DAY; uliReurn: ULINT; uliReurn_0: ULINT; uliReurn_1: ULINT; wReturn: WORD; wReturn_0: WORD; wReturn_1: WORD; wstrReturn: WSTRING; wstrReturn_0: WSTRING; END_VAR xReturn_0 := WSTRING_TO_BOOL("FALSE"); xReturn_1 := WSTRING_TO_BOOL("TRUE"); dateReturn := WSTRING_TO_DATE("DATE#2019-9-9"); dtReturn := WSTRING_TO_DT("DT#2019-9-9-1:1:1.1"); iReturn := WSTRING_TO_INT("123abc"); lrReturn := WSTRING_TO_LREAL("4.94E-323"); lrReturn_0 := WSTRING_TO_LREAL("1.7E+308"); lwReturn := WSTRING_TO_LWORD("16#FFFF_FFFF_FFFF_FFFF"); lwReturn_0 := WSTRING_TO_LWORD("16#0123456789ABCDEF"); lwReturn_1 := WSTRING_TO_LWORD("16#0123456789ABCDEF"); ltReturn := WSTRING_TO_LTIME("LTIME#213503d23h34m33s709ms551us615ns"); ltReturn_0 := WSTRING_TO_LTIME("LTIME#0ns"); ltReturn_1 := WSTRING_TO_LTIME("LTIME#1ms"); ltReturn_2 := WSTRING_TO_LTIME("LTIME#2s"); rReturn := WSTRING_TO_REAL("6.543e21"); rReturn_0 := WSTRING_TO_REAL("1.234"); timReturn := WSTRING_TO_TIME("T#5d4h3m2s"); timReturn0 := WSTRING_TO_TIME("TIME#1s"); timReturn1 := WSTRING_TO_TIME("1s"); timReturn2 := WSTRING_TO_TIME("TIME#5s"); todReturn := WSTRING_TO_TOD("TOD#12:0:0.1"); todReturn0 := WSTRING_TO_TOD("TOD#0:0:0.0"); todReturn1 := WSTRING_TO_TOD("20:15"); todReturn2 := WSTRING_TO_TOD("TOD#20:15"); uliReurn := WSTRING_TO_ULINT("18446744073709551615"); uliReurn_0 := WSTRING_TO_ULINT("1"); uliReurn_1 := WSTRING_TO_ULINT("0"); wReturn := WSTRING_TO_WORD("16#FFFF_0000"); wReturn_0 := WSTRING_TO_WORD("34abc"); wReturn_1 := WSTRING_TO_WORD("16#34abc");

FBD implementation language
