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.
Input
Input string
Number of input string's characters that are deleted
Start position of deletion, where 1 denotes 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 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.
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
if the output string is longer than the length defined for the output variable in the field "Type"
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.
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.
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
output_string:=DELETE(input_string, character_number, start_position);