Mid$ Function
Returns a substring of a string starting from a specified position.
Syntax
Mid$(string, position [, count])
Parameters
- string
- Specify the source string.
- position
- Specifies the starting position to extract the string.
- count
- Optional. The number of characters to copy from string starting with the character defined by position. If omitted, then all characters from position to the end of the string are returned.
Return Values
Returns a substring of characters from string.
Description
Mid$ returns a substring of as many as count characters starting with the position character in string.
See Also
Asc, Chr$, InStr, Left$, Len, Right$, Space$, Str$, Val
Mid$ Function Example
The example shown below shows a program that extracts the middle 2 characters from the string “ABCDEFGHIJ” and the remainder of the string starting at position 5.
Function midtest
String basestr$, m1$, m2$
basestr$ = "ABCDEFGHIJ"
m1$ = Mid$(basestr$, (Len(basestr$) / 2), 2)
Print "The middle 2 characters are: ", m1$
m2$ = Mid$(basestr$, 5)
Print "The string starting at 5 is: ", m2$
Fend