Syntax
|
Mid[$] (variable,start[,length]) = newvalue
MidB[$] (variable,start[,length]) = newvalue
|
Description
|
Replaces one part of a string with another.
|
Comments
|
The
Mid/Mid$
statements take the following parameters:
|
|
Parameter
|
Description
|
|
variable
|
String or Variant variable to be changed.
|
|
start
|
Integer specifying the character position (for Mid and Mid$ ) or byte position (for MidB and MidB$ ) within variable where replacement begins. If start is greater than the length of variable, then variable remains unchanged.
|
|
length
|
Integer specifying the number of characters or bytes to change. If this parameter is omitted, then the entire string is changed, starting at start.
|
|
newvalue
|
Expression used as the replacement. This expression must be convertible to a String.
|
|
The resultant string is never longer than the original length of variable.
With Mid and MidB , variable must be a Variant variable convertible to a String, and newvalue is any expression convertible to a string. A runtime error is generated if either variant is NULL.
Statements are used to replace the following.
|
|
Statement
|
Replaces
|
|
MidB and MidB$
|
Sub-string of bytes
|
|
Mid and Mid$
|
Sub-string of characters
|
Example
|
'This example displays a substring from the middle of a
'string variable using the Mid$ function, replacing the
'first four characters with "NEW " using the Mid$ statement.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
a$ = "This is the Main string containing text."
b$ = Mid$(a$,13,Len(a$))
Mid$(b$,1) = "NEW "
End Sub
|
See Also
|
Mid, Mid$, MidB, MidB$ (functions), Option Compare (statement)
|