</head> <body> <h1>If var [not] in/contains value1,value2,...</h1> <p>Checks whether a <a href="../Variables.htm">variable's</a> contents match one of the items in a list.</p> <pre class="Syntax"> <span class="func">if</span> Var <span class="func">in</span> MatchList <span class="func">if</span> Var <span class="func">not in</span> MatchList <span class="func">if</span> Var <span class="func">contains</span> MatchList <span class="func">if</span> Var <span class="func">not contains</span> MatchList </pre> <h2 id="Parameters">Parâmetros</h2> <dl> <dt>Var</dt> <dd><p>The name of the <a href="../Variables.htm">variable</a> whose contents will be checked. For the "in" operator, an exact match with one of the list items is required. For the "contains" operator, a match occurs more easily: whenever <em>Var</em> contains one of the list items as a substring.</p></dd> <dt>MatchList</dt> <dd><p>A comma-separated list of strings, each of which will be compared to the contents of <em>Var</em> for a match. <strong>Any spaces or tabs around the delimiting commas are significant</strong>, meaning that they are part of the match string. For example, if <em>MatchList</em> is set to <code>ABC , XYZ</code> then <em>Var</em> must contain either ABC with a trailing space or XYZ with a leading space to cause a match.</p> <p>Two consecutive commas results in a single literal comma. For example, the following would produce a single literal comma at the end of string1: <code>if Var in string1,,,string2</code>. Similarly, the following list contains only a single item with a literal comma inside it: <code>if Var in single,,item</code>. To include a blank item in the list, make the first character a comma as in this example: <code>if Var in ,string1,string2</code> (when using the "contains" operator, a blank item will always result in a match since the empty string is found in all strings).</p> <p>Because the items in <em>MatchList</em> are not treated as individual parameters, the list can be contained entirely within a variable. In fact, all or part of it must be contained in a variable if its length exceeds 16383 since that is the maximum length of any script line. For example, <em>MatchList</em> might consist of <code>%List1%,%List2%,%List3%</code> -- where each of the sublists contains a large list of match phrases.</p> <p>Any single item in the list that is longer than 16384 characters will have those extra characters treated as a new list item. Thus, it is usually best to avoid including such items.</p></dd> </dl> <h2 id="Remarks">Remarks</h2> <p>The comparison is always done alphabetically, not numerically. For example, the string "11" would not match the list item "11.0".</p> <p>The "contains" operator is the same as using <a href="InStr.htm">InStr()</a> or <a href="IfInString.htm">If[Not]InString</a> except that multiple search strings are supported (any one of which will cause a match).</p> <p><code><a href="StringCaseSense.htm">StringCaseSense</a> On</code> can be used to make the comparison case sensitive.</p> <p>If <em>MatchList</em> is long, it can be broken up into several shorter lines by means of a <a href="../Scripts.htm#continuation">continuation section</a>, which might improve readability and maintainability.</p> <p>The operators "in" and "contains" are not supported in <a href="../Variables.htm#Expressions">expressions</a>. Instead, use <a href="IfExpression.htm">If statements</a> such as <code>if (Var ~= "i)\A(Value1|Value2)\z")</code> for "in" or <code>if (Var ~= "i)Value1|Value2")</code> for "contains" to simulate the behavior of these operators.</p> <h2 id="Related">Tópicos relacionados</h2> <p><a href="IfBetween.htm">if var between</a>, <a href="IfEqual.htm">IfEqual/Greater/Less</a>, <a href="IfInString.htm">IfInString</a>, <a href="StringCaseSense.htm">StringCaseSense</a>, <a href="Block.htm">Blocks</a>, <a href="Else.htm">Else</a></p> <h2 id="Examples">Exemplos</h2> <div class="ex" id="ExInString"> <p><a class="ex_number" href="#ExInString"></a> Checks whether <var>var</var> is the file extension exe, bat or com.</p> <pre>if var in exe,bat,com MsgBox The file extension is an executable type.</pre> </div> <div class="ex" id="ExInNumber"> <p><a class="ex_number" href="#ExInNumber"></a> Checks whether <var>var</var> is the prime number 1, 2, 3, 5, 7 or 11.</p> <pre>if var in 1,2,3,5,7,11 <em>; Avoid spaces in list.</em> MsgBox %var% is a small prime number.</pre> </div> <div class="ex" id="ExContainsNumber"> <p><a class="ex_number" href="#ExContainsNumber"></a> Checks whether <var>var</var> contains the digit 1 or 3.</p> <pre>if var contains 1,3 <em>; Note that it compares the values as strings, not numbers.</em> MsgBox Var contains the digit 1 or 3 (Var could be 1, 3, 10, 21, 23, etc.)</pre> </div> <div class="ex" id="ExVar"> <p><a class="ex_number" href="#ExVar"></a> Checks whether <var>var</var> is one of the items in <var>MyItemList</var>.</p> <pre>if var in %MyItemList% MsgBox %var% is in the list.</pre> </div> <div class="ex" id="ExInputBox"> <p><a class="ex_number" href="#ExInputBox"></a> Allows the user to enter a string and checks whether it is the word yes or no.</p> <pre>InputBox, UserInput, Enter YES or NO if UserInput not in yes,no MsgBox Your input is not valid.</pre> </div> <div class="ex" id="ExWinGetTitle"> <p><a class="ex_number" href="#ExWinGetTitle"></a> Checks whether <var>active_title</var> contains "Address List.txt" or "Customer List.txt" and checks whether it contains "metapad" or "Notepad".</p> <pre>WinGetTitle, active_title, A if active_title contains Address List.txt,Customer List.txt MsgBox One of the desired windows is active. if active_title not contains metapad,Notepad MsgBox But the file is not open in either Metapad or Notepad.</pre> </div> </body> </html>