Returns the index of the first item that contains a specified substring. The search is case-sensitive. If the substring is not found in the list items, it returns zero (0).
ListContains(list, substring [, delimiters ])
Parameter |
Description |
---|---|
list |
List to search |
substring |
String sought in elements of list |
delimiters |
Set of delimiters used in list |
Note ColdFusion ignores empty list elements; thus, a list that is defined as "a,b,c,,,d" is treated as a four element list. |
<!-------------------------------------------------------------------- This example shows differences between ListContains and ListFind ----------------------------------------------------------------------> <html> <head> <title>ListContains</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>