Mid Function

Return a middle portion or sub-string from another string. You can use the Len function to determine how many characters are in a string.

Mid (string, start [, length])

Parameters

String - (Input, expression, Required)

Specifies the string from which the sub-string characters are returned. If a numeric value is passed, it is first converted into a string. If Null is passed, the result is Null. If a non-string is passed, the result is Error.

Start  -  (Input, expression, Required)

Specifies the starting character index from which the sub-string should be extracted. Index 1 specifies the first character. If the starting index is greater than the length of the string, an empty string is returned. If the starting position is less than or equal to zero, the result is Error.

Length  -  (Input, expression, Optional)

Specifies the number of the characters to return. If the length is zero, then a zero length string is returned. If the starting position plus the length is greater than the length of the string, then only the portion from the starting position onwards is returned. If the length is negative, the result is Error. If this parameter is omitted then all characters to the right of the starting position will be returned.

Return Value

A string value containing the middle portion of the passed string.

Examples

Mid (“abc”, 6)

Returns “”

Mid (“abc”, “2”)

Returns “bc”

Mid (“abc”, 2, 1)

Returns “b”

Mid (“abc”, 2, 4)

Returns “bc”

Mid (“abc”, 2, 0)

Returns “”

Mid (“abc”, -1, 1)

Returns Error

Mid (123, 2, 1)

Returns “2”

Mid (Null, 1)

Returns Null

Mid (Error, 1)

Returns Error

TIP:

Functions are specifically for use in the Macro Editor. Refer to Microsoft's official VB and JScript documentation for scripting equivalents.

See Also

Functions | Asc function | Chr function | CSet function | Format function | InStr function | LCase function | Left function | Len function | LSet function | LTrim function | Mid function | Replace function | Right function | RSet function | RTrim function | Space function | String function | TCase function | Trim function | UBound function | UCase function


© 2004-2021 looksoftware. All rights reserved.