Mid is a special statement in VB.NET that changes, or returns, a part of a String (a substring). The Mid statement is useful in string manipulation.
Mid benefits. Mid() makes String instances easier to mutate. We do not need to use Functions such as Substring. This statement can lead to clearer, shorter programs.
Example. The Mid statement is used with positional arguments. In this example, we change the part of the String from the index 2 with length 2. A new String is returned.
Next We show the Mid function, which simply returns a Substring of the String based on the positional arguments.
Detail The first argument to Mid is the string. The second and third arguments are the start index, and the length of the substring.
' Input string.
Dim value As String = "bird"' Replace part of string with another string.
Mid(value, 2, 2) = "an"' Write.
' Get middle part of string.
Dim m As String = Mid(value, 2, 2)
Implementation. Mid is compiled into the StringType.MidStmtStr subroutine, which internally validates the arguments and then uses a StringBuilder to build up the result.