Masonjar13 wrote:"If var in" doesn't support or/and. You can, however, append the two to act as an or. Otherwise, you will need a separate statement.
Code: Select all
foo:="1,2,3"
bar:="Hwnd,Qt5,Window"
;ex1
WinGetClass,C,A
if C in %foo%
doFoo()
else if C contains %bar%
doFoo()
You can also create functions for these statements, allowing you to use expression syntax, which is what I do.
Code: Select all
foo:="1,2,3"
bar:="Hwnd,Qt5,Window"
winGetClass,C,A
if(ifIn(C,foo)||ifContains(C,bar))
doFoo()
ifContains(haystack,needle){
if haystack contains %needle%
return 1
return 0
}
ifIn(needle,haystack){
if needle in %haystack%
return 1
return 0
}
Using function in AHK in not good IMO.
it would slow down the script (Tiny performance drop).
Took 0.196610
Code: Select all
Loop 100000 ; 100K call
{
WinGetTitle,T,A
if ifIn(T,"qwe,asd,zxc,wer,sdf,xcv,ert,tyu,ghj,bnm")
|| ifContains(T,"Vim")
{}
}
Took 0.114200
Code: Select all
Loop 100000 ; 100K call
{
WinGetTitle,T,A
if T in qwe,asd,zxc,wer,sdf,xcv,ert,tyu,ghj,bnm
{}
else if T contains Vim
{}
}
but it's fine, I'll keep wait until AHK newer version.
or just it can not eaily implement in C ...