ColdFusion UDF Library - StringPad

December 16th, 2008
«« Back to ColdFusion Library

Category:
   STRINGS

Description:
   Acceps a string and padds it

Parameters:
  1. string (String, required)
           any string

  2. pos (Numeric, required)
           the position of the string.

           Values:
    • Left

    • Center

    • Right

  3. size (Numeric, required)
           the size of the padding string

  4. 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
  1. No comments yet.
  1. No trackbacks yet.