The AutoHotkey documentation lists two methods of comparing a variable to items in a list.
if Var in MatchList
if Var contains MatchList
What's the difference between if var in
and if var contains
?
The AutoHotkey documentation lists two methods of comparing a variable to items in a list.
if Var in MatchList
if Var contains MatchList
What's the difference between if var in
and if var contains
?
Hopefully some examples will help demonstrate the difference.
Example of if var in MatchList
:
Match:
F3::
example := "pizza" ; Contains a matching string.
if example in This,is,a,tasty,pizza
MsgBox, %example% found in MatchList
Negative match:
F3::
example := "pizz" ; Contains no matching string.
if example not in This,is,a,tasty,pizza
MsgBox, %example% not found in MatchList
Example of if var contains MatchList
:
Match:
F3::
example := "ice" ; Contains a matching "i" substring.
if example contains p,i,z,z,a
MsgBox, %example% contains MatchList item(s)
Negative match:
F3::
example := "doggy" ; Contains no matching substring.
if example not contains p,i,z,z,a
MsgBox, %example% does not contain MatchList item(s)
Var
*contains one of the list items as a substring.* SoVar
inMatchList
is true only ifVar
is an exact match to a member ofMatchList
. ForVar
containsMatchList
to be true, an element ofMatchList
is a substring ofVar
. Note in their examples,if var contains 1,3
compares 1 and 3 as strings. So ifvar
is23
, it is true. – lurkerv in bc,xy
fails, whilev contains bc,xy
passes – Jim U