You are here: Core Reference > Coding > Logic > MID

MID

Function Name

MID

Description

Outputs a specific number of characters taken from a string input. The characters are taken from a specified position in the input string.

Arguments

IN {STRING}

The IN input is a string input. The MID function uses characters from the IN input for its output.

L {INT}

Defines the number of characters in the IN input that are used for the output.

P {INT}

Defines the starting point for the MID output. The starting point corresponds to a character in the IN string and the MID output will only include a specified number of characters from the starting point onwards. As with the other string position numbers, 1 is the first character in the string, 2 is the second, 3 is the third and so on.

For more information on the data types for the inputs and outputs, see Data Type Hierarchy.

Returns

Output {STRING}

The output is a string that is the L number of characters taken from the IN input from the P starting position.

Example:

Function Block Diagram - MID:

In this example, the IN input is 'PIPELINE', the L input is 4 and the P input is 5. This means that the MID function will return 4 characters from the IN input, starting from the fifth character. So, as the IN input is 'PIPELINE', the MID function outputs 'LINE' (4 characters from the IN input starting from the fifth character from the left).

ST Program - MID:

To use a MID function in an ST program, you need to use this syntax:

  • Output := MID ('IN', L, P);

Where Output, IN, L and P are defined as variables earlier in the ST program.

Alternatively, you can use the following syntax:

  • Output := MID (IN:= 'PIPELINE', L:= 4, P:=5);

Where the 'PIPELINE' 4 and 5 values are the input values (in this case, they are the same values as used in the Function Block Diagram example above).


ClearSCADA 2015 R2