Indent(string[, indentchar][, repeatcount])
Last updated July 17, 2001
Version: 1 | Requires: CF5 | Library: StrLib
Description:
Return string with each line prepended with indentchar repeatcount times. This function could be useful for formatting in CFMAIL or PRE tags.
A line is defined to be a string terminated by CR/LF or LF.
Return Values:
Returns a string.
Example:
<CFSAVECONTENT VARIABLE="Test">
To be or not to be, that is the question.
This is a second line of text.
And this is a third.
</CFSAVECONTENT>
<PRE>
<CFOUTPUT>
#Indent(Test)#
</CFOUTPUT>
</PRE>
Parameters:
Name | Description | Required |
---|---|---|
string | String to be modified. | Yes |
indentchar | Character to use for indenting. Defaults to tab character (Chr(9)). | No |
repeatcount | Positive integer to repeat indentchar. Defaults to 1. | No |
Full UDF Source:
/**
* Indents all the lines of a string.
*
* @param string String to be modified.
* @param indentchar Character to use for indenting. Defaults to tab character (Chr(9)).
* @param repeatcount Positive integer to repeat indentchar. Defaults to 1.
* @return Returns a string.
* @author James Ang (james@vertexcs.com)
* @version 1, July 17, 2001
*/
function Indent(str) {
var chri = CHR(9); // indenting character. Defaults to horizontal tab
var ncnt = 1; // strIndent = RepeatString(ichr, ncnt)
var strcr = CHR(13);
var strlf = CHR(10);
var strcrlf = strcr & strlf;
var strIndent = "";
if (ArrayLen(Arguments) GT 1) {
chri = Arguments[2];
if (ArrayLen(Arguments) GT 2) {
ncnt = Arguments[3];
}
}
strIndent = RepeatString(chri, ncnt);
return (strIndent & REReplace(str, "([#strcrlf#]+)([^#strcrlf#])", "\1#strIndent#\2", "ALL"));
}
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