Returns a string containing a specified number of characters from a string.
Public Shared Function Mid( _ ByVal Str As String, _ ByVal Start As Integer, _ Optional ByVal Length As Integer _ ) As String
Exception type | Error number | Condition |
---|---|---|
5 | Start <= 0 or Length < 0. |
To determine the number of characters in Str, use the Len function.
This example uses the Mid function to return a specified number of characters from a string.
Dim MyString, FirstWord, LastWord, MidWords As String MyString = "Mid Function Demo" ' Creates text string. FirstWord =Mid(
MyString,
1,
3)
' Returns "Mid". LastWord =Mid(
MyString,
14,
4)
' Returns "Demo". MidWords =Mid(
MyString,
5)
' Returns "Function Demo".
Left Function | Len Function | LTrim, RTrim, and Trim Functions | Mid Statement | Right Function |