REPLACE

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.

Parameters

Input

IN1 (STRING)

Input string

IN2 (STRING)

Replacement string

L (INT)

Number of characters in the input string to be replaced

P (INT)

Start position of the input string to be replaced, where 1 is the first character of the string

Output

Unnamed output (STRING)

Resulting string

Remarks

  • 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 Monitor > Special flags and registers > Basic error messages

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)

if a string applied at the input or output is an invalid string

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)

if a string applied at the input or output is an invalid string

Example

POU header

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

POU 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'.

LD body

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

IL body

Modified on: 2024-02-26Feedback on this pagePanasonic hotline