Home > Language Reference > String Management Functions > Mid$

Mid$

The Mid$ function extracts a substring from the specified string, starting at any position.

Usage

Used to extract a part of a string.  

Syntax

var$=Mid$(<source_string>, <start_position>, <length>)

Parameters

<source_string>, string to extract from.

<start_position>, integer, position in the string to begin extracting from. The first position in the string is 1. If <start_position> is negative, the extraction starts at position 1.

<length>, integer, number of characters to extract. 

Return value

var$, string, result of the extraction. If <length> is negative or 0, the function returns an empty string (an empty string is ""). If the length of <source_string> (including the character starting at <start_position>) is less than <length>, all the characters from <start_position> to the end of <source_string> are returned in var$.

See also

Asc
Chr$
Encrypt
ExtractBetween$
InStr
InStrRev
LCase$
Left$
Len
LTrim$
Replace$
Right$
RTrim$
SplitIntoArray
Str$
Trim$
UCase$
Val

Examples

a$ = Mid$("bcdefg",2,2) ' Returns "cd" in a$

a$ = Mid$("bcdefg",2,0) ' Returns "" in a$

a$ = Mid$("bcdefg",0,2) ' Returns "bc" in a$