CFLib.org – Common Function Library Project

ListRight(list, numElements[, delimiter])

Last updated April 24, 2002

author

Rob Brooks-Bilson

Version: 1 | Requires: CF5 | Library: StrLib

Description:
A Right() function for lists. Returns the n rightmost elements from the specified list. Accepts an optional delimiter. Note that if the number of elements to return is greater than the number of elements in the list, the UDF simply returns all elements.

Return Values:
Returns a string.

Example:

<CFSET List="1,2,3,4,5,6,7,8,9,10">
<CFSET List2="a,b,c,d,e,f,g,h">

<CFOUTPUT>
#ListRight(List, 3)#<BR>
#ListRight(List2, 50)#
</CFOUTPUT>

Parameters:

Name Description Required
list List you want to return the n rightmost elements from. Yes
numElements Number of rightmost elements you want returned. Yes
delimiter Delimiter for the list. Default is the comma. No

Full UDF Source:

/**
 * A Right() function for lists.  Returns the n rightmost elements from the specified list.
 * 
 * @param list      List you want to return the n rightmost elements from. 
 * @param numElements      Number of rightmost elements you want returned. 
 * @param delimiter      Delimiter for the list.  Default is the comma. 
 * @return Returns a string. 
 * @author Rob Brooks-Bilson (rbils@amkor.com) 
 * @version 1, April 24, 2002 
 */
function ListRight(list, numElements){
  var tempList="";
  var i=0;
  var delimiter=",";
  var totalLen=0;
  if (ArrayLen(arguments) gt 2){
    delimiter = arguments[3];
  }
  if (numElements gt ListLen(list, delimiter)){
    return list;
  }
  totalLen=ListLen(list, delimiter);
  for (i=(totalLen-numElements)+1; i LTE totalLen; i=i+1){
    tempList=ListAppend(tempList, ListGetAt(list, i, delimiter), delimiter);
  }
  return tempList;
}

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

Created by Raymond Camden / Design by Justin Johnson