# CODESYS MID

Instructions · `MID` · verification: source checked

MID is a string function in the CODESYS Standard library that returns a specified number of characters from a string, starting from a given position. It is called as MID(STR, LEN, POS): take LEN characters from STR beginning with the character at position POS, and return the partial string. The function is declared as FUNCTION MID : STRING(255).

## Specification

| Property | Value |
|---|---|
| Language | iec 61131 3 |
| Code | MID |
| Group | String Functions |
| Syntax | MID (STR, LEN, POS) |
| Dialect | CODESYS |

### Parameters

| Name | Data type | Description |
|---|---|---|
| STR | STRING(255) | String to be analyzed |
| LEN | INT | Number of characters, counted from the left |
| POS | INT | Start position for the partial string |

## Study notes

- Declared as FUNCTION MID : STRING(255), so the returned partial string can be up to 255 characters.
- All three arguments are inputs: STR (STRING(255)), LEN (INT) and POS (INT).
- The source example VarSTRING1 := MID('SUSI',2,2); returns 'US'.
- LEN is documented as the number of characters, counted from the left; POS is the start position for the partial string.

## Sources

1. [Beckhoff Information System](https://infosys.beckhoff.com/content/1033/tcplclib_tc2_standard/74420235.html) (accessed 2026-10-26)
2. [CODESYS Group](https://content.helpme-codesys.com/en/libs/Standard/Current/String-Functions/MID.html) (accessed 2026-10-26)

---

Source page: https://machineschema.com/instruction/iec-mid  
JSON: https://machineschema.com/instruction/iec-mid.json  
License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Cite Machine Schema and the original sources.
