CFLib.org – Common Function Library Project

ParagraphFormat2(string)

Last updated June 26, 2002

author

Ben Forta

Version: 3 | Requires: CF5 | Library: StrLib

Description:
An "enhanced" version of ParagraphFormat. It will replace any CR/LF combination with a <BR> tag and any double CR/LF pair with a <P> tag. The new version also replaces tabs with 3 non-breaking spaces.

Return Values:
Returns a string.

Example:

<CFSAVECONTENT VARIABLE="Text">
This is my original paragraph. It will begin with one paragraph of text, then it will continue to an address.

Raymond Camden
XXXX My Street
My City, Virginia XXXXX
</CFSAVECONTENT>

<CFOUTPUT>
The formatted version:<P>
#ParagraphFormat2(Text)#
</CFOUTPUT>

Parameters:

Name Description Required
string The string to format. Yes

Full UDF Source:

/**
 * An &quot;enhanced&quot; version of ParagraphFormat.
 * Added replacement of tab with nonbreaking space char, idea by Mark R Andrachek.
 * Rewrite and multiOS support by Nathan Dintenfas.
 * 
 * @param string      The string to format. (Required)
 * @return Returns a string. 
 * @author Ben Forta (ben@forta.com) 
 * @version 3, June 26, 2002 
 */
function ParagraphFormat2(str) {
    //first make Windows style into Unix style
    str = replace(str,chr(13)&chr(10),chr(10),"ALL");
    //now make Macintosh style into Unix style
    str = replace(str,chr(13),chr(10),"ALL");
    //now fix tabs
    str = replace(str,chr(9),"&nbsp;&nbsp;&nbsp;","ALL");
    //now return the text formatted in HTML
    return replace(str,chr(10),"<br />","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

Created by Raymond Camden / Design by Justin Johnson