MID$
Purpose
Returns a substring of a specified length from a specified position
within a string.
MID$ ( string , position [ , number of characters ] )
└─┬──┘ └──┬───┘ └─────────┬────────┘
String expression Numeric expression Numeric expression
Example
MID$(A$, 5, 3)
Parameters
- string: String expression
- position: Numeric expression truncated to an integer in the range
of 1 ≦ position < 256.
- number of characters: Numeric expression truncated to an integer
in the range of 0 ≦ number of characters < 256. The default option is
from the specified position to the end of the string when this
parameter is omitted.
Explanation
- Returns a substring of a specified length from a specified position
within a string. A substring from the specified position to the end of
the string is returned when the length of the substring is not specified.
- A substring of length 0 (null) is returned when the specified position
exceeds the length of the string.
- A substring from the specified position to the end of the string is
returned when the specified number of characters is greater than the
number of characters from the specified position to the end of the string.
See
Sample Program
10 A$="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
20 INPUT "1 TO 26 FROM"; B
30 PRINT "1 TO "; 27-B; " TO ";
40 INPUT E
50 S$ = MID$(A$, B, E)
60 PRINT S$
70 END
Uses numeric input to produce alphabetic series of a specified number
of characters starting from a specified position.