ColdFusion UDF Library - StringPad
December 16th, 2008
«« Back to ColdFusion Library
Category:
STRINGS
Description:
Acceps a string and padds it
Parameters:
Returns:
Requires:
Sample Use:
aPaddedString = StringPad("foobar was a monkey", "Left", "50", "-")
Copy to Clipboard
Category:
STRINGS
Description:
Acceps a string and padds it
Parameters:
- string (String, required)
any string - pos (Numeric, required)
the position of the string.
Values:- Left
- Center
- Right
- Left
- size (Numeric, required)
the size of the padding string - padchar (String, required)
the character you want to pad the string with
Returns:
Requires:
Sample Use:
aPaddedString = StringPad("foobar was a monkey", "Left", "50", "-")
Copy to Clipboard
function StringPad(string, pos, size, padchar){
var padsize = size - len(string);
switch(pos){
case "left":
return string & repeatString(padchar, padsize);
break;
case "center":
return repeatString(padchar, int(padsize / 2)) & string & repeatString(padChar, ceiling(padsize / 2));
break;
case "right":
return repeatString(padchar, padsize) & string;
break;
}
}
// http://www.programmers.org/index.php/coldfusion-udf-library/?ckey=72&function=StringPad



