The operators convert a 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 as 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: STRING_TO_<target type>(<operand>) , WSTRING_TO_<target type>(<operand>)
|
Operand |
Data Type |
Description |
|---|---|---|
|
Variable or literal |
STRING, WSTRING |
STRING, WSTRING |
Casting operators: STRING/WSTRING_TO_<target type>
|
Operator: STRING |
Operator: WSTRING |
Example |
Return Value |
Description |
|---|---|---|---|---|
|
STRING_TO___UXINT |
WSTRING_TO___UXINT |
__UXINT, __XINT, __XWORD |
||
|
STRING_TO___XINT |
WSTRING_TO___XINT |
__UXINT, __XINT, __XWORD |
||
|
STRING_TO___XWORD |
WSTRING_TO___XWORD |
__UXINT, __XINT, __XWORD |
||
|
STRING_TO_BIT |
WSTRING_TO_BIT |
BIT |
||
|
STRING_TO_BOOL |
WSTRING_TO_BOOL |
STRING_TO_BOOL('TRUE') STRING_TO_BOOL('true') WSTRING_TO_BOOL("TRUE") WSTRING_TO_BOOL("true") |
TRUE |
BOOL |
|
STRING_TO_BYTE |
WSTRING_TO_BYTE |
Integer |
||
|
STRING_TO_DATE |
WSTRING_TO_DATE |
STRING_TO_DATE('DATE#2019-9-9') WSTRING_TO_DATE("DATE#2019-9-9") |
D#2019-9-9 |
Syntax: D#yyyy-MM-dd Data type: DATE |
|
STRING_TO_DINT |
WSTRING_TO_DINT |
If the output data type is larger, then information may be lost. Integer |
||
|
STRING_TO_DT |
WSTRING_TO_DT |
STRING_TO_DT('DT#2019-9-9-1:1:1.1') WSTRING_TO_DT("DT#2019-9-9-1:1:1.1") |
DT#2019-9-9-1:1:1 DT#2019-9-9-1:1:1 |
Syntax: DT#yyyy-MM-dd-hh:mm:ss Data type: DATE |
|
STRING_TO_DWORD |
WSTRING_TO_DWORD |
Integer |
||
|
STRING_TO_INT |
WSTRING_TO_INT |
STRING_TO_INT('123abc') WSTRING_TO_INT("123abc") |
123 |
Integer |
|
STRING_TO_LDATE |
WSTRING_TO_LDATE |
Syntax: LDATE#yyyy-MM-dd Only the day is displayed. Data type: DATE |
||
|
STRING_TO_LDT |
WSTRING_TO_LDT |
Syntax: LDT#yyyy-MM-dd-hh:mm:ss.sss Data type: DATE |
||
|
STRING_TO_LINT |
WSTRING_TO_LINT |
Integer |
||
|
STRING_TO_LREAL |
WSTRING_TO_LREAL |
STRING_TO_LREAL('1.7E+308') WSTRING_TO_LREAL("1.7E+308") |
1.7000000000000001E+308 |
REAL, LREAL |
|
STRING_TO_LTIME |
WSTRING_TO_LTIME |
STRING_TO_LTIME('LTIME#709ms551us615ns') STRING_TO_LTIME('LTIME#1ms') WSTRING_TO_LTIME("LTIME#1ms") |
LTIME#709ms551us615ns LTIME#1ms |
Data type: TIME, LTIME |
|
STRING_TO_LTOD |
WSTRING_TO_LTOD |
Syntax: LTOD#hh:mm:ss.sssssssss Data type: DATE |
||
|
STRING_TO_LWORD |
WSTRING_TO_LWORD |
STRING_TO_LWORD('16#0123456789ABCDEF') WSTRING_TO_LWORD("16#0123456789ABCDEF") |
81985529216486895 |
Integer |
|
STRING_TO_REAL |
WSTRING_TO_REAL |
STRING_TO_REAL('1.234') WSTRING_TO_REAL("1.234") |
1.234 |
When converting from a larger value range, information may be lost or an undefined result may be returned. REAL, LREAL |
|
STRING_TO_SINT |
WSTRING_TO_SINT |
Integer |
||
|
- |
WSTRING_TO_STRING |
WSTRING_TO_STRING("Hello World!") |
Hello World! |
|
|
STRING_TO_TIME |
WSTRING_TO_TIME |
STRING_TO_TIME('T#5d4h3m2s') WSTRING_TO_TIME("T#5d4h3m2s") |
T#5d4h3m2s |
Data type: TIME, LTIME |
|
STRING_TO_TOD |
WSTRING_TO_TOD |
STRING_TO_TOD('TOD#20:15') WSTRING_TO_TOD("TOD#20:15") |
TOD#20:15:0 |
Data type: DATE |
|
STRING_TO_UDINT |
WSTRING_TO_UDINT |
Integer |
||
|
STRING_TO_UINT |
WSTRING_TO_UINT |
Integer |
||
|
STRING_TO_ULINT |
WSTRING_TO_ULINT |
STRING_TO_ULINT('615') WSTRING_TO_ULINT("615") |
615 |
Integer |
|
STRING_TO_USINT |
WSTRING_TO_USINT |
Integer |
||
|
STRING_TO_WORD |
WSTRING_TO_WORD |
Integer |
||
|
STRING_TO_WSTRING |
- |
STRING_TO_WSTRING('Hello World!') |
"Hello World!" |
WSTRING |
-
Converting to a Boolean value
-
Examples