Functions:
in
Description
Download
in.zip
Requirements
None
Functions
in(Value, MatchList, Delimiters = ",", OmitChars = "")
Modified wrapper for
if var in MatchList that makes use of a
parsing loop.
ReturnValue
If a match is found, the
index of the substring that matches the specified value.
If no match is found, the function returns 0.
Remarks
The values are compared using a
case-insensitive equal (=).
Numbers are compared
numerically.
If a match is found,
ErrorLevel is set to the matching substring. If no match is found, ErrorLevel is not changed.
Code
Code:
in(Value, MatchList, Delimiters = ",", OmitChars = "")
{
Loop, Parse, MatchList, %Delimiters%, %OmitChars%
{
if (A_LoopField = Value)
{
;store the match (as reflected in the Match list)
ErrorLevel := A_LoopField
return A_Index
}
}
return false
}
Example 1Code:
var := 5.0
;returns true - in the list
if in(var, "1,2,3,5,7,11") ;Avoid spaces in list.
MsgBox inA: %var% is a small prime number.
;returns false - not in the list
;Note that it compares the values as strings, not numbers.
if var in 1,2,3,5,7,11
MsgBox %var% is a small prime number.
if in(var, "1,2, 3, 5 , 7 , 11" , "," , " ") ;Don't worry about spaces
MsgBox inB: %var% is a small prime number.
Example 2Code:
List =
(LTrim
iTem1
ItEm2
iTem3
)
value := "item2"
;works great with continuation sections
if index := in(value, List, "`n")
{
;ErrorLevel contains the matching substring ("iTem1")
MsgBox, "%value%" matches list item %index%.`nThe matching substring is: %ErrorLevel%
}
How to use
Extract the zip's contents to a
library folder for automatic inclusion - StdLib compliant.
A copy of the above examples can be found in the "Func Examples" folder.
Download in function
_________________
As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the
Class Library. Check out
my scripts.