VBS tutorial: function mid function


Mid function

Returns a specified number of characters from a string.

Mid(string, start[, length])



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


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


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.


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.