Mid
Use the Mid function to return a specified number of characters from as string.
Syntax
Mid(string, start[, length])
Argument | Description |
---|---|
string |
String expression from which characters are returned. If string contains Null, then Null is returned. |
start |
Character position in string at which the part to be taken begins. If start is greater than the number of characters in string, then Mid returns a zero-length string (""). |
length |
Number of characters to return. If omitted, or total number of characters are fewer than length , then all characters from the start to the end position are returned. |
To determine the number of characters in a string, use the Len
function.
Examples
-
Dim MyVar MyVar = Mid("VB Script is fun!", 4, 6)
This example returns a string that is six characters long and starts with the fourth character in the string:
MyVar = "Script"
Mid("This is the middle of this sentence",9,10)
This example returns "the middle":