listContains

Description

Determines the index of the first list element that contains a specified substring.

Categories

Related

Syntax

ListContains(list, substring [, delimiters, includeEmptyValues ])

Attributes

AttributeDescriptionRequiredDefault
delimitersA string or a variable that contains one. Characters 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.
includeEmptyValuesOptional. Set to yes to include empty values.
listA list or a variable that contains one.
substringA string or a variable that contains one. The search is case sensitive.

Returns

Index of the first list element that contains substring. If not found, returns zero.

Usage

ColdFusion ignores empty list elements; thus, the list "a,b,c,,,d" has four elements.

Example

<!--- 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")> 
Here is a list: <cfoutput>#aList#</cfoutput> 
<strong>ListContains</strong> checks for substring "wo" in the list elements: 
<cfoutput> 
    &nbsp;&nbsp;&nbsp;Substring "wo" is in  
    <B>element #ListContains(aList, "wo")#</B> of list. 
</cfoutput> 
ListFind cannot check for a substring within an element; therefore, in the  
    code, it does not find substring "wo" (it returns 0): 
<cfoutput> 
    &nbsp;&nbsp;&nbsp;Substring "wo" is in <b>element #ListFind(aList, "wo")# 
    </b> of the list.</cfoutput> 
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: 
    &nbsp;&nbsp;&nbsp;<strong>ListContains</strong>:  
<cfoutput> 
The string "two" is in <b>element #ListContains(aList, "two")#</b> of the list. 
</cfoutput> 
&nbsp;&nbsp;&nbsp;<strong>ListFind</strong>:  
<cfoutput> 
The string "two" is in <b>element #ListFind(aList, "two")#</b> of the list. 
</cfoutput>