CFLib.org – Common Function Library Project

cfStringFormat(mystring)

Last updated May 9, 2003

author

Isaac Dealey

Version: 1 | Requires: CF5 | Library: StrLib

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:

/**
 * 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); 
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson