CFLib.org – Common Function Library Project

rjustify2(string, length)

Last updated December 21, 2011

author

Al Everett

Version: 0 | Requires: CF5 | Library: UtilityLib

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

Return Values:
Returns a string.

Example:

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

Parameters:

Name Description Required
string String to manipulate. Yes
length Length of pad. Yes

Full UDF Source:

/**
 * Same as built-in RJUSTIFY, but allows optional parameter character to pad with.
 * 
 * @param string 	 String to manipulate. (Required)
 * @param length 	 Length of pad. (Required)
 * @return Returns a string. 
 * @author Al Everett (everett.al@gmail.com) 
 * @version 0, December 21, 2011 
 */
function rjustify2(string,length) {
	var padChar = " ";
	if (arrayLen(arguments) GT 2) {
		padChar=left(arguments[3],1);
	}
		
	return repeatString(padChar,max(0,arguments.length - len(arguments.string))) & 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