Replaces characters
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.
Input
Input string
Replacement string
Number of characters in the input string to be replaced
Start position of the input string to be replaced, where 1 is the first character of the string
Output
Resulting string
If this instruction is used with UTF-8 strings, please refer to the notes concerning UTF-8 strings under the data type STRING.
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
if a string applied at the input or output is an invalid string
if a string applied at the input or output is an invalid string
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
output_value: STRING[32]:='';
END_VAR
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'.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_VARIN,,'MrSpock',6,1,8,3,);
B(B_VARIN,,'o',6,2,8,4,);
B(B_VARIN,,1,6,3,8,5,);
B(B_VARIN,,6,6,4,8,6,);
B(B_VAROUT,,output_value,14,1,16,3,);
B(B_F,REPLACE!,Instance,8,0,14,6,,?DIN1?DIN2?DL?DP?C);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY