MID

Returns a substring from the middle of a string.

Signature

    ┌─────────┐
IN ─┤         │
 L ─┤   MID   ├─ OUT
 P ─┤         │
    └─────────┘
FUNCTION MID : ANY_STRING
  VAR_INPUT
    IN : ANY_STRING;
    L  : ANY_INT;
    P  : ANY_INT;
  END_VAR
END_FUNCTION

The return type matches the type of IN. MID accepts STRING for IN; L and P are INT.

Inputs

Name

Type

Description

IN

ANY_STRING

The source string.

L

INT

Number of characters to extract.

P

INT

Starting position (1-based).

Outputs

Name

Type

Description

Return value

ANY_STRING

L characters from IN starting at position P. Same type as IN.

Description

MID(IN, L, P) returns L characters from IN starting at position P. Positions are 1-based: the first character is at position 1.

Example

result := MID('Hello World', 5, 1);   (* result = 'Hello' *)
result := MID('Hello World', 5, 7);   (* result = 'World' *)

See Also

  • LEFT — left substring

  • RIGHT — right substring

  • LEN — string length

References