Conversion instructions
215
Part II IEC Instructions
LD
ST
When programming with structured text, enter the following:
result_string:=DWORD_TO_STRING(input_value);
Example 2
This example illustrates how you create STRING[10] out of the data type DWORD in which the
leading part of the string '16#' is replaced by the string '0x'.
The example is programmed in LD and IL. The same POU header is used for both programming
languages.
POU header
In this example the input variables input_value of the data type DWORD and an output variable
result_string of the data type STRING[10] are declared.
Body
In carrying out the operation in question, the standard function REPLACE is attached to the
function DWORD_TO_STRING. REPLACE replaces one section of a character string with another.
In the example, the output string of DWORD_TO_STRING function is added at input IN1 of the
REPLACE function. At input IN2, the STRING constant '0x' is added as the replacement STRING.
At the L input of REPLACE, the INT constant 3 determines the length of the STRING to be
replaced. The P input determines the position at which the replacement begins. In this case it is the
INT number 1. From the variable input_value = 16#12345678, the result_string = '0x12345678'
results after undergoing the data type conversion and REPLACE function.
LD