VB6Parse / Library / String / mid_dollar

VB6 Library Reference

Mid$ Function

The Mid$ function returns a String containing a specified number of characters from a string. The dollar sign suffix ($) indicates that this function always returns a String type, never a Variant.

Syntax

Mid$(string, start[, length])

Parameters

Return Value

Returns a String containing the specified portion of the input string.

Behavior

Difference from Mid

The Mid$ function always returns a String, while the Mid function (without the dollar sign) can return a Variant. In practice, they behave identically in most scenarios, but the dollar sign version may be slightly more efficient as it avoids the overhead of the Variant type.

Examples

' Extract 3 characters starting at position 2
Dim result As String
result = Mid$("Hello World", 2, 3)  ' Returns "ell"

' Extract from position 7 to the end
result = Mid$("Hello World", 7)  ' Returns "World"

' Start position beyond string length
result = Mid$("Hi", 10)  ' Returns ""

← Back to String | View all functions