AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Func] in - modified wrapper for: if var in MatchList

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Sat Apr 11, 2009 8:35 pm    Post subject: [Func] in - modified wrapper for: if var in MatchList Reply with quote

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 1
Code:
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 2
Code:
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.


Last edited by animeaime on Sun Apr 12, 2009 5:41 pm; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail
BoBoł
Guest





PostPosted: Sat Apr 11, 2009 10:03 pm    Post subject: Reply with quote

Thx Very Happy
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group