Name
Mid Statement
Syntax
Mid(target, start[, length]) = string-
target Use: Required
Data Type: String
The name of the string variable to be modified
-
start Use: Required
Data Type: Long
The position within
stringvarat which the replacement commences-
length Use: Optional
Data Type: Long
The number of characters in
stringvarto replace-
string Use: Required
Required: String
The string used to replace characters within
stringvar
Description
Replaces a section of a string with characters from another string
Rules at a Glance
If you omit
length, as many characters ofstringas can fit intostringvarare used.If
start+lengthis greater then the length ofstringvar,stringis truncated to fit in the same space asstringvar. This means that the length ofstringvaris not altered by theMidstatement.If
startis less than 0, runtime error 5, “Invalid procedure call or argument,” occurs.
Programming Tips and Gotchas
If
stringisNothing, a runtime error occurs.VB includes the
Replacefunction, which enhances the functionality of theMidstatement by allowing you to specify the number of times the replacement is carried out in the same string.Because it is a statement, this version of
Middoes not accept named arguments.As a statement,
Midis implemented by the compiler, rather than by the Microsoft.VisualBasic.Strings class.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access