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

Replaces a specified number of characters with characters from another string.


stringvarThe text string (String).
startThe character position to start (Long).
length(Optional) The number of characters to return (Long).
stringThe string expression that replaces part of stringvar (String).

REMARKS
* This statement will replace a specified number of characters in a string variable.
* The number of characters replaced is always less than or equal to the number of characters in stringvar.
* The first character position is 1.
* You can use the MID Function to return the text string which is a substring of a larger string.
* For more information, refer to the Replacing Strings page.
* For the Microsoft documentation refer to docs.microsoft.com

Dim sText As String 
sText = "hello world"
Mid(sText, 1, 3) = "XXX"
Debug.Print sText '= "XXXlo world"

sText = "hello world"
Mid(sText, 7, 3) = "XXX"
Debug.Print sText '= "hello XXXld"

sText = "The dog jumps"
Mid(sText, 5, 3) = "fox"
Debug.Print sText '= "The fox jumps"

Mid(sText, 5) = "cow"
Debug.Print sText '= "The cow jumps"

Mid(sText, 5) = "cat runs fast"
Debug.Print sText '= "The cat runs"

Mid(sText, 5, 3) = "rabbit"
Debug.Print sText '= "The rab runs"

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited Top