CFLib.org – Common Function Library Project

ArrayContains(arrayToSearch, valueToFind)

Last updated March 31, 2003
Download UDF

author

Sudhir Duddella                                   Sudhir Duddella

Version: 1 | Requires: ColdFusion 5 | Library: DataManipulationLib

Description:
Returns the index of the first item that contains a specified substring. The search is case-sensitive. If the substring is not found in an Array, it returns zero (0).

Return Values:
Returns a number.

Example:

<cfset arrN = arrayNew(1)>
<cfset arrN[1] = "A">
<cfset arrN[2] = "AP">
<cfset arrN[3] = "B">
<cfset arrN[4] = "APPLE">
<cfset arrN[5] = "BOY">
<cfset arrN[6] = "BOUGHT">

<cfoutput>#ArrayContains(arrN,"OU")#</cfoutput>

Output:
6

Parameters:

Name Description Required
arrayToSearch Array to search. Yes
valueToFind Value to look for. Yes

Full UDF Source:

<cfscript>
/**
* Returns the index of the first item in an array that contains a specified substring.
* Mods by RCamden
*
* @param arrayToSearch      Array to search. (Required)
* @param valueToFind      Value to look for. (Required)
* @return Returns a number.
* @author Sudhir Duddella (skduddella@hotmail.com)
* @version 1, March 31, 2003
*/

function ArrayContains(arrayToSearch,valueToFind){
    var arrayList = "";

    arrayList = ArrayToList(arrayToSearch);
    return ListContains(arrayList,valueToFind);                
}
</cfscript>

Search CFLib.org


Latest Additions

Jose Diaz-Salcedo Jose Diaz-Salcedo added
cfRssFeed
3 day(s) ago

Raymond Compton Raymond Compton added
structBlend
23 day(s) ago

Duncan Duncan added
IsZIPUK
23 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
29 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson