dice(str, size[, sep])
Last updated April 24, 2012
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);
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016