ListReverse(list[, delimiter])
Last updated July 17, 2001
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;
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016