CFLib.org – Common Function Library Project

padDirection(string, char, number[, charD])

Last updated May 9, 2003

author

Ron Gambill

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Basic padding function that allows user to decide which side of the submitted string that the characters should be added to (via L or R). See also padString().

Return Values:
Returns a string.

Example:

<cfset aString="Fred">
<cfoutput>
#padDirection(aString,"X",10,"R")#
</cfoutput>

Parameters:

Name Description Required
string String to pad. Yes
char Character to use as pad. Yes
number Number of characters to pad. Yes
charD Direction to pad. Should be "L" (left) or "R" (right). Defaults to R. No

Full UDF Source:

/**
 * Basic padding function that allows user to decide which side of the submitted string that the characters should be added to (via L or R).
 * 
 * @param string 	 String to pad. (Required)
 * @param char 	 Character to use as pad. (Required)
 * @param number 	 Number of characters to pad. (Required)
 * @param charD 	 Direction to pad. Should be "L" (left) or "R" (right). Defaults to R. (Optional)
 * @return Returns a string. 
 * @author Ron Gambill (rgambill@hotmail.com) 
 * @version 1, May 9, 2003 
 */
function padDirection(string,char,number) {
   // set up variables
   var strLen = len(string);
   var padLen = number - strLen;
   var returnValue = string;
   var charD = "R";

   if(arrayLen(arguments) gte 4) charD = arguments[4]; 
   if (strLen gte number) return string;
   
   if (charD eq "R") return string & RepeatString(char, padLen);
   else return RepeatString(char, padLen) & string;
}
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