Copy characters from the right
RIGHT copies, starting from the right, n characters of the string of the first input variable to the output variable. You define the number of characters to be delivered n by the second input variable.
Input
1st input: input string
2nd input: number of input string's characters that are copied, from the right
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.
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
sInput: STRING[15]:='abcd efg hijk';
(*sample string*)
iChar_number: INT:=4;
(*characters to be delivered*)
sResult: STRING[4]:='';
(*result here= 'hijk'*)
END_VAR
In this example the input variables (sInput and iChar_number) have been declared. Instead, you may enter the string ('abcd efg hijk') 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 right, iChar_number (4) of sInput ('abcd efg hijk’) is copied to sResult ('hijk’).
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,RIGHT!,Instance,10,0,15,4,,?DIN?DL?C);
B(B_VARIN,,sInput,8,1,10,3,);
B(B_VARIN,,iChar_number,8,2,10,4,);
B(B_VAROUT,,sResult,15,1,17,3,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
sResult:=RIGHT(IN := sInput, L := iChar_number);
LD |
sInput |
RIGHT |
iChar_number |
ST |
sResult |