INSERT

Insert characters

INSERT inserts the string IN2 into the string IN1 beginning after the character position P, where 0 denotes the beginning of the string, 1 the position after the first string character etc. The result is written into the output variable.

Parameters

Input

IN1 (STRING)

input string

IN2 (STRING)

string to be inserted into input string

P (INT)

position after which string IN2 is inserted into input string IN1, where 0 denotes the beginning of the string, 1 the position after the first string character

Output

Unnamed output (STRING)

result 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 (IN1 and IN2) in the declaration field “Type”, an error occurs (see sys_bIsCarry for error handling).

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
		input_string1: STRING[32]:='ideas life';
		input_string2: STRING[32]:='for';
		position: INT:=6;
		output_string: STRING[32]:='';
	END_VAR

POU body

In this example the input variables input_string1, input_string2 and position have been declared. However, you may enter the values directly at the function's input contact pins instead. The STRING values have to be put in inverted commas, both in the POU header and at the contact pins. input_string2 ('for ') is inserted into input_string1 ('Ideas life') after character position 6. The result ('Ideas for life') is returned at output_value. In the LD example, (Monitoring) icon was activated while in online mode, hence you can see the results immediately.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,INSERT!,Instance,9,0,14,5,,?DIN1?DIN2?DP?C);
B(B_VARIN,,input_string1,7,1,9,3,);
B(B_VARIN,,input_string2,7,2,9,4,);
B(B_VARIN,,position,7,3,9,5,);
B(B_VAROUT,,output_string,14,1,16,3,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

output_value:=INSERT(IN1:=input_string1, IN2:=input_string2, P:=6);

IL body

Modified on: 2022-03-02Feedback on this pagePanasonic hotline