CFLib.org – Common Function Library Project

cfStringFormat(mystring)

Last updated May 9, 2003

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

 
Rated 4 time(s). Average Rating: 4.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:

view plain print about
<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:

view plain print about
<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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
4 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson