Sysstrlen, string length

List

This page is part of the IEC 61131-3 Programming Manual. Go to the index.

This function returns the length (Expressed in number of characters excluding the terminator) of the string defined by the parameter Str.

information circle

Function

CODESYS: eCDSXUnified12Lib

LogicLab: eLLabXUnified12Lib

Description

Str (@STRING Pointer to the string of which to calculate length.

The function returns a variable (UDINT) which indicates the number of characters in the string excluding the terminator.

Sysstrlen function image

Examples

How to use the examples.
The example calculates the length of the string 'Hello!'and the number of characters that make up the string is transferred to the variable Length. The result of the calculation is 6.

LogicLab (Ptp116)
PROGRAM ST_Sysstrlen
VAR
    Length : ARRAY[ 0..1 ] OF UDINT; (* String length *)
    DString : STRING[ 32 ] := 'Hello!'; (* Data string *)
END_VAR

// *****************************************************************************
// PROGRAM "ST_Sysstrlen"
// *****************************************************************************
// It's calculated the length of a given string.
// -----------------------------------------------------------------------------

    Length[0]:=Sysstrlen(ADR('Hello!'));
    Length[1]:=Sysstrlen(ADR(DString));

// [End of file]
CODESYS (Ptp161)
PROGRAM ST_Sysstrlen
VAR
    Length : ARRAY[ 0..1 ] OF UDINT; //String length
    DString : STRING[ 32 ] := 'Hello!'; //Data string
END_VAR

// *****************************************************************************
// PROGRAM "ST_Sysstrlen"
// *****************************************************************************
// It's calculated the length of a given string.
// -----------------------------------------------------------------------------

    Length[0]:=Sysstrlen(ADR('Hello!'));
    Length[1]:=Sysstrlen(ADR(DString));

// [End of file]
Was this article helpful?