Mid Statement

Replaces the specified number of symbols in the string of Variant (String) type with symbols from another string.

Syntax

Mid(stringvar, start[, length]) = string

The Mid statement syntax has these parts:

Элемент Описание
stringvar Required. Name of the string variable to be changed.
start Required. Value of Variant (Long) type. Defines the position of the symbol in the variable from where to start replacing.
length Optional. Value of Variant (Long) type. Defiines the number of symbols to be replaced. If this argument is omitted, the entire string will be used.
string Required. String expression, that serves to replace a part of string variable.

Remarks

The number of replaced symbols can't exceed the number of symbols in the variable.

Example

This example shows how the Mid statement is used to replace the specified number of symbols of the string variable with symbols from another string.

Dim MyString
MyString = "The dog jumps" ' Initialize string.
Trace MyString
Mid(MyString, 5, 3) = "fox" ' MyString = "The fox jumps".
Trace MyString
Mid(MyString, 5) = "cow" ' MyString = "The cow jumps".
Trace MyString
Mid(MyString, 5) = "cow jumped over" ' MyString = "The cow jumpe".
Trace MyString
Mid(MyString, 5, 3) = "duck" ' MyString = "The duc jumpe".
Trace MyString

See Also

Mid Function