Actually, now the thread can stay:
Code:
InList(var, matchlist)
{ ; function by [VxE]. Alternate for 'If Var [Not] In Matchlist'
; return value is 0 if the string contained in var does not match
; any item in matchlist. Otherwise, the return value is the number
; of the item in matchlist that first matched var.
StringReplace, var, var, `,, % Chr(4), all
StringReplace, matchlist, matchlist, `,`,, % Chr(4), all
matchlist := SubStr("_," matchlist, 1, 1 + InStr("," matchlist ",","," var ","))
StringReplace, matchlist, matchlist, `,,`,, UseErrorLevel
return ErrorLevel
}
needle = bar
haystack = yoo,foo,bar
MsgBox % "'"needle "' found in '" haystack "' at item " InList(needle, haystack)
I've only done a bit of testing, but the output seems to be consistent with the behavior stated in the comments. Its behavior also seems to be analogous to the 'If _ [Not] In _' that it emulates. I've tested matching an empty string, as well as a string with commas. If someone would like to test further and post the error cases, I'll be happy to update.
I was actually thinking about this after reading
jaco0646's post... though that was resolved previously.