RIGHT block

Short summary

Name

RIGHT

→POU type

→function

Category

IEC-block, String, block with internal error diagnostic

Conform to →IEC-standard

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/error.svg currently restricted
(IEC demands data type ANY_STRING for the input IN and the return value, hence the following data type is demanded as well: WSTRING. Currently, this data type is not supported for the block.)

Graphical interface

images/download/thumbnails/414782680/RIGHT-version-1-modificationdate-1535103376723-api-v2.png

Available since

version 1.32.0 (for logi.CAD 3)

Functionality

The block returns a partial string of another string – starting at the rightmost position.

At input IN, enter a string. At input L, enter the number of characters to return (= the length of the part to return).

Special cases (see under "Example for usage within ST-editor" ) :

  • In case of L = 0, the block returns an empty string ''. In this case, the output ENO is set to value TRUE.

  • If the value for L is > the length of the string value for IN, the block returns the string as connected to IN. In this case, the output ENO is set to value FALSE.

  • If a negative value is connected to L, the block returns an empty string ''. In this case, the output ENO is set to value FALSE as well.

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg logi.CAD 3 determines the character positions within a string as follows: 1, 2, ..., n. 1 corresponds to the leftmost character position and n to the length of the string.
Three-character combination of the dollar sign ($) followed by two hexadecimal digits are evaluated as single character. Example: The string '$B15' (corresponds to '±5') consists of 2 characters. See →character string literal for more examples for those combinations.

Inputs, return value


Identifier

→Data type

Description

Inputs:

IN

STRING

input value

L

USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT(corresponds to →generic data type ANY_INT)

number of characters to return

Return value:

STRING


Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

Internal error diagnostic for block

The block checks the would-be return value.

If the return value cannot be mapped in the available memory (the return value is too large), the output ENO of the block is set to value FALSE (or an equivalent). When you are using nested blocks with STRING values, observe that the memory for STRING values is restricted (see "In case of nested string blocks: How can the return value be entirely mapped ?" for details and examples).
Moreover, the block checks the connected values whether a non-existent character position in a string is accessed. This is the case, if the value for L is > the length of the string value for IN or a negative value is connected to L. The output ENO of the block is set to value FALSE (or an equivalent) in both these cases.

Example for usage within ST-editor

PROGRAM Test
VAR
result1, result3, result4, result5, result6 : STRING[8];
result2 : STRING[2];
CheckENO1, CheckENO2, CheckENO3, CheckENO4, CheckENO5, CheckENO6 : BOOL;
END_VAR
result1 := RIGHT(IN := 'astring', L := 3, ENO => CheckENO1);
(* The variable 'result1' evaluates to <'ing'>. The variable 'CheckENO1' evaluates to 'TRUE'. *)
result2 := RIGHT(IN := 'astring', L := 3, ENO => CheckENO2);
(* The variable 'result2' evaluates to <'in'>. The variable 'CheckENO2' evaluates to 'FALSE'. Reason: 'result2' is declared with length '2' and the would-be return value exceeds this length. *)
result3 := RIGHT(IN := 'astring', L := 0, ENO => CheckENO3);
(* The variable 'result3' evaluates to <''>, i.e an empty string. The variable 'CheckENO3' evaluates to 'TRUE'. Reason: value '0' for 'L' *)
result4 := RIGHT(IN := 'astring', L := 10, ENO => CheckENO5);
(* The variable 'result4' evaluates to <'astring'>. The variable 'CheckENO4' evaluates to 'FALSE'. Reason: value for 'L' > the length of string 'astring' *)
result5 := RIGHT(IN := 'astring', L := -2, ENO => CheckENO5);
(* The variable 'result5' evaluates to <''>, i.e an empty string. The variable 'CheckENO5' evaluates to 'FALSE'. Reason: negative value for 'L' *)
result6 := RIGHT(IN := 'deviation: $B15', L := 2, ENO => CheckENO6);
(* The variable 'result6' evaluates to <'$B15'>, i.e an empty string. The variable 'CheckENO6' evaluates to 'TRUE'. *)
END_PROGRAM

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.