MID - Return the middle part of a string

Introduction

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

Informal Syntax:

MID( InValue, LValue, PValue )

Formal Syntax:

MID( In:=InValue, L:=LValue, P:=PValue )

Parameters

ParameterTypeDescription
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.

Examples

ExampleReturn Value
MID('', 1, 1)STRING#''
MID('Abcde', 3, 2)STRING#'bcd'
MID(In:="Abcdef", L:=3, P:=4)WSTRING#"ef"

Standards Compliance

Table 29.4 - IEC 61131-3 2nd Edition.

Table 34.4 - IEC 61131-3 3rd 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.

Glossary

For definitions of the terms used in Fernhill SCADA.