CFLib.org – Common Function Library Project

ListReverse(list[, delimiter])

Last updated July 17, 2001

author

Stephen Milligan

Version: 2 | Requires: CF5 | Library: StrLib

Description:
Reverses a list.

Return Values:
Returns a list.

Example:

<CFSET myList = "apples,oranges,pears,bananas">
<CFSET ReversedList = ListReverse(myList)>
<CFOUTPUT>
myList: #myList#<BR>
ReversedList: #ReversedList#
</CFOUTPUT>

Parameters:

Name Description Required
list List to be modified. Yes
delimiter Delimiter for the list. Defaults to a comma. No

Full UDF Source:

/**
 * Reverses a list.
 * Modified by RCamden to use var scope
 * 
 * @param list 	 List to be modified. 
 * @param delimiter 	 Delimiter for the list. Defaults to a comma. 
 * @return Returns a list. 
 * @author Stephen Milligan (spike@spike.org.uk) 
 * @version 2, July 17, 2001 
 */
function ListReverse(list) {

	var newlist = "";
	var i = 0;
	var delims = "";
	var thisindex = "";
	var thisitem = "";
	
	var argc = ArrayLen(arguments);
	if (argc EQ 1) {
		ArrayAppend(arguments,',');
	}
	delims = arguments[2];
	while (i LT listlen(list,delims))
	{	
	thisindex = listlen(list,delims)-i;
	thisitem = listgetat(list,thisindex,delims);
    newlist = listappend(newlist,thisitem,delims);
    i = i +1;
	}
 return newlist;
}
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