VBS tutorial: function mid function

Time:2021-10-27

Mid function

Returns a specified number of characters from a string.

Mid(string, start[, length])

parameter

string

A string expression from which characters are returned. IfstringContains null, returnsNull

Start

stringThe starting position of the extracted character part in the. IfstartMore thanstringThe number of characters in the,MidA zero length string (”) will be returned.

Length

The number of characters to return. If omitted orlengthExceeds the number of characters in the text, includingstartCharacter at) will be returned from the stringstartAll characters to the end of the string.

explain

To judgestringThe number of characters in, which can be usedLenFunction.

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

Dim myvarmyvar = mid ("VB script is fun!, 4, 6) 'myvar contains" script ".

be careful MidBFunction is used with byte data contained in a string. Its parameter is not the specified number of characters, but the number of bytes.