MID$ function

Purpose: MID$ returns a substring of a string.


Syntax:

 SubStr = MID$(MainStr AS STRING, _
                Start AS INTEGER  _
            [, Length AS INTEGER])

Return Value:

  • Data type: STRING
    SubStr substring extracted from MainStr$.

Parameters:

  • Data type: STRING
    MainStr String from which SubStr$ is extracted.
  • Data type: INTEGER
    Start Integer specifying the start position of the SubStr$ to be extracted from MainStr$.
  • Data type: INTEGER
    Length [OPTIONAL] Length of the substring to be extracted. This can be omitted if all the characters to the right of Start% are to be retrieved.

Remarks:

It is the responsibility of the programmer to ensure that the receiving string is large enough to hold the string being returned from MID$.

Example 1 :


 DIM SubStr$
 SubStr$ = MID$("abcdefg", 3, 4)
 PRINT SubStr$

Result:


 cdef

Example 2:


 DIM SubStr$
 SubStr$ = MID$("abcdefg", 2)
 PRINT SubStr$

Result:


 bcdefg

BCX Console Sample Programs using MID$ function.

S17.bas S23.bas S39.bas S55.bas S61.bas S84.bas S87.bas S110.bas