ListContains

Returns the index of the first element of a list that contains the specified substring within elements. The search is case-sensitive. If no element is found, returns zero (0).

See also ListContainsNoCase and ListFind.

Syntax

ListContains(list, substring [, delimiters ])
list

List being searched.

substring

String being sought in elements of list.

delimiters

Set of delimiters used in list.

Examples

<!--- This example shows ListContains --->
<HTML>
<HEAD>
<TITLE>ListContains Example</TITLE>
</HEAD>

<BASEFONT FACE="Arial, Helvetica" SIZE=2>
<BODY  bgcolor="#FFFFD5">
<H3>ListContains Example</H3>

<CFIF IsDefined("form.letter") OR IsDefined("form.yourCity")>
    <!--- First, query to get some values for our list --->
    <CFQUERY NAME="GetLocations" DATASOURCE="HRAPP">
    SELECT     Location
    FROM    Departments
    WHERE   <CFIF form.yourCity is "">Location LIKE '#form.letter#%' 
<CFELSE>Location='#form.yourCity#'</CFIF>
    </CFQUERY>
    
    <CFSET tempList = ValueList(GetLocations.location)>
    <CFIF ListContains(tempList, form.yourCity) OR form.yourCity is "" 
AND GetLocations.RecordCount Is Not 0>
    <P><CFIF form.yourCity is "" >You didn't specify a city, but using 
<CFOUTPUT>#form.letter#</CFOUTPUT> to determine
        a location, we found the following information.
       </CFIF>
     <CFQUERY NAME="GetInformation" DATASOURCE="HRAPP">
        SELECT Department_Name, Location
        FROM Departments
        WHERE <CFIF form.yourCity is "">Location LIKE '#form.letter#%' 
<CFELSE>Location LIKE '#form.yourCity#%'</CFIF>
        </CFQUERY>
        <UL>
        <CFOUTPUT query="GetInformation">
            <LI><B>A #Department_Name# Department is in <I>#location#</
I></B>
        </CFOUTPUT>
        </UL>
    <CFELSE>
    <P>Sorry, no Allaire offices in your city; however, Allaire has a 
partnership program that you may 
       wish to investigate <a href="http://www.allaire.com/partners/
index.cfm">Partnership Program</a>.
    </CFIF>
</CFIF>


<FORM ACTION="listcontains.cfm" METHOD="POST">
Letter City begins with:
<SELECT name="Letter">
    <OPTION value="A">A
    <OPTION value="B">B
    <OPTION value="C" SELECTED>C
    <CFSET temp ="D">
    <CFLOOP FROM="1" TO="25" INDEX="Counter">
    <OPTION value="<CFOUTPUT>#temp#">#Temp#</CFOUTPUT>
    <CFSET temp = CHR(Evaluate(Asc(temp) + 1))>
    </CFLOOP>
</SELECT>
<P>Name of your city: <INPUT TYPE="Text" NAME="YourCity" VALUE="">
<BR>(<I>hint: try "C" or "S", "Cambridge"</I>)
<INPUT TYPE="Submit" NAME="Find an Allaire office">
</FORM>
</BODY>
</HTML>