MID - Return the middle part of a string


Returns the middle n characters of a string starting at a specified offset.

Informal Syntax:

MID( In, L, P )

Formal Syntax:

MID( In:=expression, L:=expression, P:=expression )


InANY_STRINGThe input string.
LANY_INTThe number of characters to return.
PANY_INTThe 1-based starting offset.

Return value

The function MID returns L characters from string In starting at position P.

The type of the return value is the same as the type of the In parameter.

The position parameter P is 1-based, where 1 represents the first character, 2 represents the second character, and so on.

If P is zero or negative, the starting position will be the first character in In. If P is greater than the length of In, an empty string will be returned.

Note: Watch carefully the ordering of the parameters. A number of other languages support a function similar to MID but the parameter order is String, Offset, Length.


ExampleReturn Value
MID('', 1, 1)STRING#''
MID('Informs', 4, 3)STRING#'form'
MID(In:="Informed", L:=8, P:=3 )WSTRING#"formed"

Standards Compliance

Table 29.4 - IEC 61131-3 Second Edition.

Table 34.4 - IEC 61131-3 Third Edition.

Note: The function allows negative values for the L and P parameters. The IEC 61131-3 standard states this should be an error.

Note: The function allows the L and P parameters to specify a location outside the input string. The IEC 61131-3 standard states this should be an error.

Further Information

String Functions

To learn about other String Functions.

Common Elements

To learn about other IEC 61131-3 Common Elements.


For the meaning of terms used in Fernhill SCADA.