CFLib.org – Common Function Library Project

dice(str, size[, sep])

Last updated April 24, 2012

author

Richard

Version: 1 | Requires: CF5 | Library: StrLib

Description:
Divide a string in parts of equal size separated by a character sequence of choice. Default separator is the wbr tag. Handy if you need to put long words in a very small space, like an HTML table with many columns.

Return Values:
Returns a string.

Example:

<cfoutput>#dice("Supercalifragilisticexpialidocious",10)#</cfoutput>	

<cfoutput>#dice("Supercalifragilisticexpialidocious",10,"-")#</cfoutput>

Parameters:

Name Description Required
str String to dice Yes
size Size of the resulting parts Yes
sep Separator between resulting parts No

Full UDF Source:

/**
 * Divide a string in parts of equal size with separators in between/
 * 
 * @param str 	 String to dice (Required)
 * @param size 	 Size of the resulting parts (Required)
 * @param sep 	 Separator between resulting parts (Optional)
 * @return Returns a string. 
 * @author Richard (acdhirr@trilobiet.nl) 
 * @version 1, April 24, 2012 
 */
function dice(str,size) {

	var r = "";
	var i = 0;
	var sep = "<wbr/>";	

	if (arrayLen(arguments) GT 2 ) sep = arguments[3];
	
	for ( i=0; i LT len(str); i=i+1 ) {
		if ( (i-size+1) mod size eq 1) r&=sep; 
		r &= str.charAt(i);
	}	
	
	return trim(r);
}
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