IfInString / IfNotInString

Checks if a variable contains the specified string.

IfInString, Var, SearchString
IfNotInString, Var, SearchString
Position := InStr(Haystack, Needle [, CaseSensitive?, StartingPos]]) ; See the InStr() function for details.



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


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


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.


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


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