If[Not]InString

AutoHotkey GUI

If[Not]InString

Checks if a variable contains the specified string.

Deprecated: These commands are not recommended for use in new scripts. Use the InStr function instead.

IfInString, Var, SearchString
IfNotInString, Var, SearchString

Parameters

Var

The name of the variable whose contents will be searched for a match.

SearchString

The string to search for. Matching is not case sensitive unless StringCaseSense has been turned on.

Remarks

The built-in variables %A_Space% and %A_Tab% contain a single space and a single tab character, respectively, which might be useful when searching for these characters alone.

Another command can appear on the same line as this one. In other words, both of these are equivalent:

IfInString, MyVar, abc, Gosub, Process1
IfInString, MyVar, abc
    Gosub, Process1

However, items other than named commands are not supported on the same line. For example:

IfInString, MyVar, abc, found := true  ; Invalid.

Related

InStr(), RegExMatch(), StringGetPos, StringCaseSense, IfEqual, if var in/contains MatchList, if var between, if var is type, Blocks, Else

Example

Haystack = abcdefghijklmnopqrs
Needle = abc
IfInString, Haystack, %Needle%
{
    MsgBox, The string was found.
    return
}
else
    Sleep, 1