CFLib.org – Common Function Library Project

ArrayFindNoCase(arrayToSearch, valueToFind)

Last updated September 6, 2002

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

 
Rated 4 time(s). Average Rating: 4.0

Description:
Returns the index in an array containing a given (case-insensitive) value. It is analagous to listFind(), but with arrays. See also arrayFind().

Return Values:
Returns a number.

Example:

view plain print about
<cfscript>
    anArray = arrayNew(1);
    anArray[1] = "Camden";
    anArray[2] = "Archibald";
    anArray[3] = "Mueller";
    anArray[4] = "Dintenfass";
</cfscript>

<cfoutput>#arrayFindNoCase(anArray,"MUELLER")#</cfoutput>

Parameters:

Name Description Required
arrayToSearch The array to search. Yes
valueToFind The value to look for. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Like listFindNoCase(), but for arrays.
 * 
 * @param arrayToSearch      The array to search. (Required)
 * @param valueToFind      The value to look for. (Required)
 * @return Returns a number. 
 * @author Nathan Dintenfass (nathan@changemedia.com) 
 * @version 1, September 6, 2002 
 */

function ArrayFindNoCase(arrayToSearch,valueToFind){
    //a variable for looping
    var ii = 0;
    //loop through the array, looking for the value
    for(ii = 1; ii LTE arrayLen(arrayToSearch); ii = ii + 1){
        //if this is the value, return the index
        if(NOT compareNoCase(arrayToSearch[ii],valueToFind))
            return ii;
    }
    //if we've gotten this far, it means the value was not found, so return 0
    return 0;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
30 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson