Mid - Built-in String Function¶
Purpose¶
The Mid function returns a substring of specified length and position from the value of the input string.
Syntax¶
Mid(str, int1 [,int2])
Arguments¶
| Argument | Required | Description |
|---|---|---|
str |
Yes | Any valid string expression from which the specified number of characters are returned. |
int1 |
Yes | Any valid integer expression. Starting position of the characters in str to return. int1 is one-based. |
int2 |
No | Any valid integer expression. Number of characters to return. |
Returns¶
Variant with a string (VT_BSTR) value
Example¶
Let sTest = "Mid Function Demo"
Let sRet1 = Mid(sTest, 1, 3) // = "Mid"
Let sRet2 = Mid(sTest, 14) // = "Demo"
Let sRet3 = Mid(sTest, 5, 8) // = "Function"
Return (sRet1 * sRet2 * sRet3) // returns "Mid Demo Function"
See Also¶
Notes¶
- When the arguments cannot be converted to the specified type, a runtime error is generated.
- If
int1is greater than the number of characters instr, the function returns an empty string (""). - If
int2is omitted or if it is greater than or equal to the number of characters instrfromint1, the entire string from the start position is returned.