DELETE

Delete characters from a string

DELETE deletes L characters in the string IN starting at position P, where 1 denotes the first character of the string. The result is written into the output variable.

Parameters

Input

IN (STRING)

Input string

L (INT)

Number of input string's characters that are deleted

P (INT)

Start position of deletion, where 1 denotes 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 output string is longer than the length defined for the output variable in the field “Type”, only as many characters are copied as the output variable can hold.The system variable sys_bIsCarry is set.

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

sys_bIsCarry (turns to TRUE for one scan)

if the output string is longer than the length defined for the output variable in the field "Type"

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_string: STRING[15]:='Ideas for life';
		character_number: INT:=8;
		start_position: INT:=6;
		output_string: STRING[5]:='';
	END_VAR

In this example the input variables (input_string, character_number and start_position) have been declared. Instead, you may enter the string ('Ideas for life'), the number of characters to be deleted and the start position directly into the function. The string has to be put in inverted commas, both in the POU header and in the function.

POU body

Starting from start_position(6), character_number (8) is deleted from input_string ('Ideas for life’). The resulting string ('Ideas') is written into output_string.

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,DELETE!,Instance,10,0,16,5,,?DIN?DL?DP?C);
B(B_VARIN,,input_string,8,1,10,3,);
B(B_VARIN,,character_number,8,2,10,4,);
B(B_VARIN,,start_position,8,3,10,5,);
B(B_VAROUT,,output_string,16,1,18,3,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

output_string:=DELETE(input_string, character_number, start_position);

IL body

Modified on: 2022-06-28Feedback on this pagePanasonic hotline