StringMid - Syntax & Usage | AutoHotkey

AutoHotkey

StringMid

Retrieves one or more characters from the specified position in a string.

Deprecated: This command is not recommended for use in new scripts. Use the SubStr function instead.

StringMid, OutputVar, InputVar, StartChar , Count, L

Parameters

OutputVar

The name of the variable in which to store the substring extracted from InputVar.

InputVar

The name of the variable from whose contents the substring will be extracted. Do not enclose the name in percent signs unless you want the contents of the variable to be used as the name.

StartChar

The position of the first character to be extracted, which can be an expression. Unlike StringGetPos, 1 is the first character. If StartChar is less than 1, it will be assumed to be 1. If StartChar is beyond the end of the string, OutputVar is made empty (blank).

Count

[v1.0.43.10+]: This parameter may be omitted or left blank, which is the same as specifying an integer large enough to retrieve all characters from the string.

Otherwise, specify the number of characters to extract, which can be an expression. If Count is less than or equal to zero, OutputVar will be made empty (blank). If Count exceeds the length of InputVar measured from StartChar, OutputVar will be set equal to the entirety of InputVar starting at StartChar.

L

The letter L can be used to extract characters that lie to the left of StartChar rather than to the right. In the following example, OutputVar will be set to Red:

InputVar = The Red Fox
StringMid, OutputVar, InputVar, 7, 3, L

If the L option is present and StartChar is less than 1, OutputVar will be made blank. If StartChar is beyond the length of InputVar, only those characters within reach of Count will be extracted. For example, the below will set OutputVar to Fox:

InputVar = The Red Fox
StringMid, OutputVar, InputVar, 14, 6, L

Remarks

For this and all other commands, OutputVar is allowed to be the same variable as InputVar.

Related

SubStr(), StringLeft, StringRight, StringTrimLeft, StringTrimRight, IfInString, StringGetPos, StringLen, StringLower, StringUpper, StringReplace

Example

Source = Hello this is a test. 
StringMid, the_word_this, Source, 7, 4