Copy characters from the left
LEFT copies, starting from the left, n characters of the string of the first input variable to the output variable. You define the number of characters L to be delivered by the second input variable.
Input
input string
number of input string's characters that are copied, from the left
Output
copied 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 number of characters to be delivered is greater than the input string, the complete string will be copied to the output variable output_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';
(*sample string*)
output_string: STRING[5]:='';
(*result: here 'Ideas'*)
character_number: INT:=5;
(*characters to be delivered*)
END_VAR
In this example the input variables (input_string and character_number) have been declared. Instead, you may enter the string ('Ideas for life') and the number of characters to be delivered directly into the function. The string has to be put in inverted commas, both in the POU header and in the function.
Starting from the left, character_number (5) of input_string ('Ideas for life’) is copied to output_string ('Ideas’).
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 4 ;
NETWORK_BODY
B(B_F,LEFT!,Instance,11,0,16,4,,?DIN?DL?C);
B(B_VARIN,,input_string,9,1,11,3,);
B(B_VARIN,,character_number,9,2,11,4,);
B(B_VAROUT,,output_string,16,1,18,3,);
L(1,0,1,4);
END_NETWORK_BODY
END_NET_WORK
END_BODY
output_string:=LEFT(IN:=input_string, L:=character_number);
LD |
input_string |
LEFT |
character_number |
ST |
output_string |