CFLib.org – Common Function Library Project

ListPad(list, char, strLen[, delimiter])

Last updated December 7, 2001

author

Rob Brooks-Bilson

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Applys padding to each element in a list. Padding is applied to each element so that all elements have the same length. If an element in the list has a greater length than that specified in the strLen parameter, no padding is applied to the element.

Return Values:
Returns a list.

Example:

<CFSET x="1234567,23,2354,45,7435,23,2,5352,353455,2298744,274,9,04">

<CFOUTPUT>
#ListPad(x, 0, 7)#
</CFOUTPUT>

Parameters:

Name Description Required
list List to apply the padding to. Yes
char Character to use as the padding. Yes
strLen Length to pad each list item out to. No padding will be applied oif the length of the list item is greater than or equal to strLen. Yes
delimiter Delimiter for the list. Default is the comma. No

Full UDF Source:

/**
 * Applys padding to each element in a list.
 * 
 * @param list 	 List to apply the padding to. 
 * @param char 	 Character to use as the padding. 
 * @param strLen 	 Length to pad each list item out to.  No padding will be applied oif the length of the list item is greater than or equal to strLen. 
 * @param delimiter 	 Delimiter for the list.  Default is the comma. 
 * @return Returns a list. 
 * @author Rob Brooks-Bilson (rbils@amkor.com) 
 * @version 1, December 7, 2001 
 */
function ListPad(list, char, strLen)
{
  Var PaddedList = "";
  Var PadLen = 0;
  Var Delimiter = ",";
  Var i=0;
  if (ArrayLen(arguments) gt 3){
    Delimiter = arguments[4];
  }
  for (i=1; i LTE ListLen(list, delimiter); i=i+1){
    PadLen = strLen-Len(ListGetAt(list, i, delimiter));
    if (PadLen GTE 0){
		  PaddedList = ListAppend(PaddedList, RepeatString(char, PadLen) & ListGetAt(list, i, delimiter), delimiter);
    }
    else {
      PaddedList = ListAppend(PaddedList, ListGetAt(list, i, delimiter), delimiter);
    }
  }
  Return PaddedList;
}
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