MID$

Function

MID$ returns a substring of given length starting at the given position. It may also be used as a statement.

Syntax

B$=MID$ (A$,X, [Y])

or

MID$ (A$,X,[Y]) = C$

Examples

10 A$= "ABCDEFGH"
20 PRINT MID$ (A$,3,4)

Prints CDEF

Remarks

A$, X or Y may be expressions. If Y is omitted then all characters to the right of the Xth character are returned.

In the above example:

MID$ (A$,0,3) = 'ABC'
MID$ (A$,20,5) = null string
MID$ (A$,7) = 'GH'

When MID$ is used as a statement in the form:

MID$(A$,X[,Y])=C$

its sets the part of A$ starting at the Xth character with the substring C$. The optional parameter Y denotes the length of the part of A$ to be replaced and if omitted defaults to the length of C$.