Good morning,

The ListContains function does not work as you wish it to. You should use
the ListFind and ListFindNoCase functions. Here is what the docs say about
ListFind. I use this quite a bit.

ListFind
        Returns the index of the first occurrence of a value within a list. Returns
0 if no value is found. The search is case-sensitive.

See also ListContains and ListFindNoCase.

Syntax
ListFind(list, value [, delimiters ])

list
List being searched.

value
Number or string that is to be found in the items of the list.

delimiters
Set of delimiters used in the list.

Examples

<!----------------------------------------------------------------------
This example shows differences between ListContains and ListFind
----------------------------------------------------------------------->
<HTML>
<HEAD>
    <TITLE>ListFind/TITLE>
</HEAD>

<BODY>
<!----------------------------------------------------------------------
Create a list composed of the items one, two, three.
----------------------------------------------------------------------->
<CFSET aList="one">
<CFSET aList=ListAppend(aList, "two")>
<CFSET aList=ListAppend(aList, "three")>
<P>
Here is the list: <B><CFOUTPUT>#aList#</CFOUTPUT></B>
<P>
ListContains checks for the existence of a substring "wo" in the items in
the list.
<BR>ListContains<BR>
<CFOUTPUT>
The substring "wo" is in <B>Item #ListContains(aList, "wo")#</B> of the
list.
</CFOUTPUT>
<P>
ListFind cannot check for substrings within items; therefore, in the
following code where ListFind in used in place of ListContains, it will
not find the substring "wo" in the list.
<BR>ListFind<BR>
<CFOUTPUT>
The substring "wo" is in <b>Item #ListFind(aList, "wo")#</b> of the list.
</CFOUTPUT>
<P>
However, if you specify the entire string <B>two</B>, both ListContains
and ListFind will find it in the second item in the list.
<BR>ListContains<BR>
<CFOUTPUT>
The string "two" is in <b>Item #ListContains(aList, "two")#</b> of the
list.
</CFOUTPUT>
<BR>ListFind<BR>
<CFOUTPUT>
The string "two" is in <b>Item #ListFind(aList, "two")#</b> of the list.
</CFOUTPUT>
</BODY>
</HTML>


Don Lundgren ;-)


-----Original Message-----
From: van Wyk, Carlo [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 19, 2001 4:28 AM
To: CF-Talk
Subject: Listcontains question


Hi

I have the following piece of code that checks to see if a user can see a
specific pageid or not. Unfortunately it is not doing the job as I have a
list that looks something like this:

4,14,3,2,8,44

If the user is allowed to see page 4, then he would be able to see all pages
that contains a 4, so it does not work correctly.


<cfif listcontains(newlist,  "#pageid#")>
                <cfinclude template=#page#>
        <cfelse>
        <cfoutput>
        #application.securityerror#
        </cfoutput>
</cfif>

Regards
Carlo
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to