CFLib.org – Common Function Library Project

PadString(string, char, count)

Last updated August 16, 2001

author

Rob Brooks-Bilson

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Pads a string with n characters. Padding is from the left.

Return Values:
Returns a string.

Example:

<CFSET x=123>
<CFSET y="test">

<CFOUTPUT>
#PadString(x, 0, 4)#<BR>
#PadString(y, "a", 5)#
</CFOUTPUT>

Parameters:

Name Description Required
string String you want to pad. Yes
char Character to use as the padding. Yes
count Number of characters to pad the string with. Yes

Full UDF Source:

/**
 * Pads a string with n characters.  Padding is from the left.
 * 
 * @param string      String you want to pad. 
 * @param char      Character to use as the padding. 
 * @param count      Number of characters to pad the string with. 
 * @return Returns a string. 
 * @author Rob Brooks-Bilson (rbils@amkor.com) 
 * @version 1, August 16, 2001 
 */
function PadString(string, char, count)
{
  var Padding = RepeatString(char, count);
  return Padding & string;
}

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