SoFunction
Updated on 2025-04-10

VBS Tutorial: Functions - Mid Functions

Mid function

Returns the specified number of characters from the string.

Mid(string, start[, length])

parameter

string

A string expression from which characters are returned. ifstringInclude Null, returnNull

Start

stringThe starting position of the extracted character part in it. ifstartMore thanstringThe number of characters inMidReturns a zero-length string ("").

Length

The number of characters to return. If omitted orlengthThe number of characters exceeding the text (includingstartcharacter at) will return the string fromstartAll characters to the end of the string.

illustrate

To judgestringThe number of characters in it can be usedLenfunction.

The following example usesMidThe function returns six characters in the string starting from the fourth character:

Dim MyVarMyVar = Mid("VBscriptis fun!", 4, 6) 'MyVar Include "Script"

Notice MidBFunctions are used with byte data contained in strings. Its parameters are not specified characters, but bytes.