CFLib.org – Common Function Library Project

numTextListSort(list)

Last updated January 12, 2004

author

Matt

Version: 1 | Requires: CF6 | 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:

<cfscript>
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:

/**
 * 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);
	
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson