LEN

String length

LEN calculates the length of the input string and writes the result into the output variable.

Parameters

Input

Unnamed input (STRING)

input data type

Output

Unnamed output (INT)

length of 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 strings are longer than the length defined for the input variables (IN1 and IN2) in the declaration field “Type”, an error occurs (see sys_bIsCarry for error handling).

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

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[12]:='Panasonic';
			(*sample string*)
		output_value: INT:=0;
			(*result: here 9*)
	END_VAR

In this example the input variable (input_string) has been declared. Instead, you may enter the string ('Panasonic') directly into the function. The string has to be put in inverted commas, both in the POU header and in the function.

POU body

The length (9) of input_string ('Panasonic’) is written into output_value.

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 2 ;
        NETWORK_BODY
B(B_F,LEN!,Instance,9,0,14,2,,?DIN?C);
B(B_VARIN,,input_string,7,0,9,2,);
B(B_VAROUT,,output_value,14,0,16,2,);
L(1,0,1,2);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

output_value:=LEN(input_value);

IL body

LD

input_value

LEN

ST

output_value

Modified on: 2022-03-02Feedback on this pagePanasonic hotline