Determines the index of the first list element that contains a specified substring.
Index of the first list element that contains substring. If not found, returns zero.
ListContains(list,substring[,delimiters])
ListContainsNoCase, ListFind; "Lists" in the ColdFusion Developer's Guide
|
Parameter |
Description |
|---|---|
| list |
A list or a variable that contains one. |
| substring |
A string or a variable that contains one. The search is case-sensitive. |
| delimiters |
A string or a variable that contains one. Character(s) that separate list elements. The default value is comma. If this parameter contains more than one character, ColdFusion processes each occurrence of each character as a delimiter. |
ColdFusion ignores empty list elements; thus, the list "a,b,c,,,d" has four elements.
<!--- This example shows differences between ListContains and ListFind --->
<!--- Create a list composed of the elements one, two, three. ---->
<cfset aList = "one">
<cfset aList = ListAppend(aList, "two")>
<cfset aList = ListAppend(aList, "three")>
<p>Here is a list: <cfoutput>#aList#</cfoutput>
<p><strong>ListContains</strong> checks for substring "wo" in the list elements:
<cfoutput>
<p> Substring "wo" is in
<B>element #ListContains(aList, "wo")#</B> of list.
</cfoutput>
<p>ListFind cannot check for a substring within an element; therefore, in the
code, it does not find substring "wo" (it returns 0):
<cfoutput>
<p> Substring "wo" is in <b>element #ListFind(aList, "wo")#
</b> of the list.</cfoutput>
<p><p>If you specify a string that exactly equals an entire list element, such
as "two", both ListContains and ListFind find it, in the second element:
<p> <strong>ListContains</strong>:
<cfoutput>
The string "two" is in <b>element #ListContains(aList, "two")#</b> of the list.
</cfoutput>
<p><strong>ListFind</strong>:
<cfoutput>
The string "two" is in <b>element #ListFind(aList, "two")#</b> of the list.
</cfoutput>