[ahkv2] how to if var in/contains matchlist Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [ahkv2] how to if var in/contains matchlist

10 Aug 2018, 02:54

It is not implemented in v2 (yet?)
You can use a custom function, eg,

Code: Select all

var_in(var, list){
	if type(list) == 'String'
		list := strsplit(list, ',')
	for k, v in list
		if var = v
			return k
	return false
}
; Example
var := 'cat'
if var_in(var, 'dog,parrot,fish,apple,cat')
	msgbox 'yes'

var := 2
if var_in(var, [1,2,3,4])
	msgbox 'yes'

var := 5
if var_in(var, [1,2,3,4])
	msgbox 'yes'
else 
	msgbox 'no'
There are many other ways to do it.

Cheers
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [ahkv2] how to if var in/contains matchlist  Topic is solved

10 Aug 2018, 04:34

shorthand regex instead of in

Code: Select all

if ("dog,parrot,fish,apple,cat" ~= "\bcat\b")
	MsgBox("yes")
else
	MsgBox("no")
rodemp
Posts: 44
Joined: 15 Nov 2016, 00:28

Re: [ahkv2] how to if var in/contains matchlist

10 Aug 2018, 23:38

swagfag wrote:shorthand regex instead of in

Code: Select all

if ("dog,parrot,fish,apple,cat" ~= "\bcat\b")
	MsgBox("yes")
else
	MsgBox("no")
Awesome!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Exies, hiahkforum, JoeWinograd, scriptor2016 and 101 guests