CFLib.org – Common Function Library Project

cfStringFormat(mystring)

Last updated May 9, 2003
Download UDF

author

Isaac Dealey                                      Isaac Dealey

Version: 1 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 0 time(s). Average Rating: 0

Description:
escapse all double-quotes and pound symbols in a string and replaces all ascii non-printing characters with a #chr(x)# equivalent

Return Values:
Returns a string.

Example:

<cfset str = "<cfset x = " & "##z## plus hello"">">
<cfoutput>
str = #htmlEditFormat(str)#<br>
cfStringFormat(str) = #htmlEditFormat(cfstringformat(str))#
</cfoutput>

Parameters:

Name Description Required
mystring String to format. Yes

Full UDF Source:

<cfscript>
/**
* companion to jsstringformat - formats a string for use as a coldfusion literal value
*
* @param mystring      String to format. (Required)
* @return Returns a string.
* @author Isaac Dealey (info@turnkey.to)
* @version 1, May 9, 2003
*/

function cfStringFormat(mystring) {
    var x = 0;
    var npc = "";
    var npcc = "";

    mystring = rereplacenocase(mystring,"(""|##)","\1\1","ALL");
    for (x = 1; x lte 31; x = x + 1) {
        npc = listappend(npc,chr(x));
        npcc = listappend(npcc,"##chr(#x#)##");
    }
    return replacelist(mystring,npc,npcc);
}
</cfscript>

Search CFLib.org


Latest Additions

Ryan Thompson-Jewell Ryan Thompson-Jewell added
ListSplit
3 day(s) ago

Nathan Dintenfass Nathan Dintenfass added
RowsToColumns
3 day(s) ago

Barney Boisvert Barney Boisvert added
indentXml
4 day(s) ago

Barney Boisvert Barney Boisvert added
REReplaceCallbac...
4 day(s) ago

Top Rated

Rob Brooks-Bilson                                 FolderSize
Rated 5.0, 7 time(s)

Nick Giovanni                                     UniqueValueList
Rated 5.0, 5 time(s)

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Jeff Howden ListDeleteDuplic...
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson