Mid$ Function/Assignment

Syntax

Mid[$](S$, Index[, Len])
-or-
Mid[$](strvar, Index[, Len]) = S$

Group

String

Description

Function - Returns the substring of S$ starting at Index for Len chars.

Instruction: - Assigns S$ to the substring in strvar starting at Index for Len chars.

NOTE: A similar function, MidB, returns the Len bytes starting a byte Index.

Parameters

Parameter Description (Mid Function)
S$ Copies chars from this string value. If this value is Null, Null is returned.
Index Starts copying chars starting at this index value. If the string is not that long, it returns a null string.
Len Copies this many chars. If the S$ does not have that many chars starting at Index, it copies the remainder of S$.

 

Parameter Description (Mid Assignment)
strvar Changes part of this string.
Index Changes strvar starting at this index value. If the string is not that long then it is not changed.
Len The number of chars copied is smallest of: the value of Len, the length of S$ and the remaining length of strvar. (If this value is omitted, the number of chars copied is the smallest of: the length of S$ and the remaining length of strvar.)
S$ Copies chars from this string value.

Example


Sub Main
    S$ = "Hello There"
    Mid$(S$,7) = "?????????"
    Debug.Print S$ '"Hello ?????"
    Debug.Print Mid$("Hello",2,1) '"e"
End Sub

See also

InStr( ), Left$( ), Len( ), Replace$( ), Right$( )