numTextListSort(list)
Last updated January 12, 2004
Version: 1 | Requires: ColdFusion MX | Library: StrLib
Description:
This function returns a sorted list that has numeric and text values starting with the numeric and ending with the text values.
Return Values:
Returns a string.
Example:
myList='cash,car,12,5,4,3,2,1,11,10,9,8,7,6,home';
writeoutput(numTextListSort(myList));
</cfscript>
Parameters:
| Name | Description | Required |
|---|---|---|
| list | List to sort. | Yes |
Full UDF Source:
<cfscript>
/**
* This function is to be used, to sort a list that has numeric and text values.
*
* @param list List to sort. (Required)
* @return Returns a string.
* @author Matt (Coldfusion@spiraldev.com)
* @version 1, January 12, 2004
*/
function numTextListSort(list) {
var numArray=arrayNew(1);
var textArray=arrayNew(1);
var mg = 1;
var data = "";
//convert to array for speed
data = listToArray(list);
//loop through the list passed to the function
for(;mg lte arrayLen(data);mg=mg+1){
//if the value at this position of the list is numeric put it in the numList List
if(isNumeric(data[mg])) numArray[arrayLen(numArray)+1] = data[mg];
//else put it in the textList List
else textArray[arrayLen(textArray)+1] = data[mg];
}
//sort the numList
arraySort(numArray,"numeric");
//sort the textList
arraySort(textArray,"text");
//put together
for(mg=1;mg lte arrayLen(textArray);mg=mg+1) {
numArray[arrayLen(numArray)+1] = textArray[mg];
}
//return the mainList
return arrayToList(numArray);
}
</cfscript>
Search CFLib.org
Latest Additions
Shawn Porter added
DeMoronize
3 hour(s) ago
Chris Carey added
readPropertiesFi...
1 day(s) ago
Randy Johnson added
lastDayofWeek
3 day(s) ago
Frank Marion added
sitemapPing
7 day(s) ago
Top Rated
QuickSort
Rated 5.0, 3 time(s)
indentXml
Rated 5.0, 3 time(s)
queryColumnsToSt...
Rated 5.0, 3 time(s)
generateSsccAsn
Rated 5.0, 3 time(s)