Mid Statement
The document is archived and information here might be outdated

Mid Statement

Replaces a specified number of characters in a String variable with characters from another string.

Mid( _
   ByRef Target As String, _
   ByVal Start As Integer, _
   Optional ByVal Length As Integer _
) = StringExpression

Parts

Target
Required. Name of the String variable to modify.
Start
Required. Integer expression. Character position in Target where the replacement of text begins. Start uses a one-based index.
Length
Optional. Integer expression. Number of characters to replace. If omitted, all of String is used.
StringExpression
Required. String expression that replaces part of Target.

Remarks

The number of characters replaced is always less than or equal to the number of characters in Target.

Note   The MidB statement of earlier versions of Visual Basic replaces a substring in bytes, rather than characters. It is used primarily for converting strings in double-byte character set (DBCS) applications. All Visual Basic .NET strings are in Unicode, and MidB is no longer supported.

Example

This example uses the Mid statement to replace a specified number of characters in a string variable with characters from another string.

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

Requirements

Namespace: Microsoft.VisualBasic

Module: Strings

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

See Also

Strings | String Manipulation | Mid Function

Show:
© 2016 Microsoft