Mid statement
Replaces a specified number of characters in a Variant (String) variable with characters from another string.
Syntax
Mid(stringvar, start, [ length ] ) = string
The Mid statement syntax has these parts:
Part | Description |
---|---|
stringvar | Required. Name of string variable to modify. |
start | Required; Variant (Long). Character position in stringvar where the replacement of text begins. |
length | Optional; Variant (Long). Number of characters to replace. If omitted, all of string is used. |
string | Required. String expression that replaces part of stringvar. |
Remarks
The number of characters replaced is always less than or equal to the number of characters in stringvar.
Note
Use the MidB statement with byte data contained in a string. In the MidB statement, start specifies the byte position within stringvar where replacement begins, and length specifies the numbers of bytes to replace.
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
MyString = "The dog jumps" ' Initialize 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".
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기