CFLib.org – Common Function Library Project

ljustify2(string, length[, padChar])

Last updated September 16, 2012

author

Al Everett

Version: 0 | Requires: CF5 | Library: StrLib

Description:
This function mimics the lJustify function, but offers an optional third parameter to define the character to use for padding (if padding is necessary).

Return Values:
Returns a string, left-justified and padded to the specified field length

Example:

<cfoutput>
#ljustify2("foobar",10,".")#<br> <!--- outputs: foobar.... --->
#ljustify2("foobar",5,"-")#<br> <!--- outputs: foobar --->
</cfoutput>

Parameters:

Name Description Required
string A string to justify within the specified field length Yes
length The length of the field within which to justify the string Yes
padChar Character to use for padding No

Full UDF Source:

/**
 * Same as built-in LJUSTIFY, but allows optional parameter character to pad with.
 * version 1.0 by Al Everett
 * 
 * @param string 	 A string to justify within the specified field length (Required)
 * @param length 	 The length of the field within which to justify the string (Required)
 * @param padChar 	 Character to use for padding (Optional)
 * @return Returns a string, left-justified and padded to the specified field length 
 * @author Al Everett (everett.al@gmail.com) 
 * @version 0, September 16, 2012 
 */
function ljustify2(string,length) {
	var padChar = " ";
	if (arrayLen(arguments) GT 2) {
		padChar=left(arguments[3],1);
	}
		
	return arguments.string & repeatString(padChar,max(0,arguments.length - len(arguments.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