CFLib.org – Common Function Library Project

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

Last updated December 07, 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;
}

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