REPLACE

REPLACE

PROGRAM REPLACE_DEMO
   VAR
   IN1,IN2,OUT1: STRING;
   L1, P1: INT;
  END_VAR
    OUT1:=REPLACE(IN1:=IN1,IN2:=IN2,L:=L1,P:=P1);
END_PROGRAM

The REPLACE function replaces part of the input string in1 by another string, in2. The starting position “p” must be greater than 0 and less than the total number of characters in the string in1. If the replaced part is out of the input string, it is a input parameter error. If the “l” and “p” values are entered falsely, there is an exception and the PLC stops. If stop on exception is disabled, the function output gives the last correct value.

InputType Description
IN1 ANY_STRINGInput string, of which a part will be replaced
IN2 ANY_STRINGInput string which will replace the omitted part
L ANY_INT Length of the deleted part
P ANY_INT Position where the deleted part starts, if at the first character, p=1
OutputType Description
ANY_STRINGOutput string

  • © Energocentrum Plus, s.r.o. 2017 - 2024