CFLib.org – Common Function Library Project

ArrayListCompareNoCase(arrayToSearch, listToFind [, delimiter])

Last updated March 28, 2005

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

 
Rated 0 time(s). Average Rating: 0

Description:
Returns the index in an array containing one of the given (case-insensitive) list elements or 0 if none found.

Return Values:
Returns a number.

Example:

view plain print about
<cfset l = "a,b,c,d">
<cfset a = ArrayNew(1)>
<cfset a[1] = "e">
<cfset a[2] = "d">
<cfset a[3] = "ab">

<cfoutput>#ArrayListCompareNoCase(a, l)#</cfoutput>

Parameters:

Name Description Required
arrayToSearch The array to search. Yes
listToFind List that will be searched for. If any item is found, the array index is returned. Yes
delimiter List delimiter. Defaults to a comma. No

Full UDF Source:

view plain print about
<cfscript>
/**
 * Returns the index of the first item in an array that contains a list element.
 * 
 * @param arrayToSearch      The array to search. (Required)
 * @param listToFind      List that will be searched for. If any item is found, the array index is returned. (Required)
 * @param delimiter      List delimiter. Defaults to a comma. (Optional)
 * @return Returns a number. 
 * @author Steve Robison, Jr (steverobison@gmail.com) 
 * @version 1, March 28, 2005 
 */

function ArrayListCompareNoCase(arrayToSearch,listToFind){
    //a variable for looping
    var ii = 0;        // variable for looping through list
    var jj = 0;        // variable for looping through array
    var delimiter = ',';        // default delimiter
    

    // check to see if delimiters were passed
    if (ArrayLen(arguments) gt 2) delimiter = arguments[3];

    //loop through list
    for(ii = 1; ii LTE ListLen(listToFind, delimiter); ii = ii + 1) {
    //loop through the array, looking for the value
    for(jj = 1; jj LTE arrayLen(arrayToSearch); jj = jj + 1){
        //if this is the value, return the index
        if(NOT compareNoCase(arrayToSearch[jj],ListGetAt(listToFind, ii, delimiter)))
            return jj;
    }
    }
    //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