String instructions
278
Part II IEC Instructions
REPLACE
Replaces characters
To add an enable input and enable output to the instruction, select [With EN/ENO] from the
"Instructions" pane (LD, FBD or IL editor). To reuse an instruction select "Recently used" from the
context menu or press <Ctrl>+<Shift>+<v> in the programming window.
PLC types
Availability of REPLACE (see page 1330)
If the strings are longer than the length defined for the input variables
(input_string_1 and input_string_2) in the field "Type", an error occurs
(see Special Internal Relays for Error Handling).
The number of steps may vary depending on the PLC and parameters
used, see also Table of Code Intensive Instructions in the online help.
(up to 200 steps)
Data type I/O Function
STRING 1st input input string
STRING 2nd input replacement string
INT 3rd input the number of characters in the input string to be replaced
INT 4th input position at which characters begin to be replaced
STRING output resulting string
No. IEC address Set If
R9007 %MX0.900.7 permanently
R9008 %MX0.900.8 for an instant
input strings are longer than the length
defined for the input variables in the field
"Type"
Description
REPLACE replaces the characters in the string IN1 with P denoting the first position to be replaced
and L denoting the number of characters to be replaced with the characters specified by IN2. The
result is written into the output variable.
Data types
Error flags
Example
In this example, the same POU header is used for all programming languages. For an example
using IL (instruction list), please refer to the online help.
POU header
All input and output variables which are required for programming the function are declared in the
POU header.
Body
In this example constant values are entered directly at the function's input contact pins. However,
you may declare variables in the POU header. The STRING values have to be put in inverted
commas, either in the POU header or at the contact pins. Here the 'c' in the STRING 'MrSpock' has
been replaced with an 'o', yielding 'MrSpook'.