Remove carriage returns from a string
Quite often I need to remove carriage returns and usually I use the following code:
Replace(myvar,”#chr(13)#”,”",”ALL”);
However I have found this doesn’t always remove the carriage returns.
How did I fix it? I used the following code:
REReplace(myvar,”#chr(13)#|\n|\r”,”",”ALL”);
This works everytime, its very handy for writing html with javascript
for example:
<cfsavecontent variable=”thecode”>
<cfinclude template=”#dynamicCFMfile#”>
</cfsavecontent>
<cfscript>
newDefaultCode = Replace(thecode ,”"”",”\”"”,”ALL”);
newDefaultCode = REReplace(newDefaultCode ,”#chr(13)#|#chr(9)#|\n|\r”,”",”ALL”);
</cfscript>
<cfoutput>theHTML = “#newDefaultAdCode#”;</cfoutput>
document.write(theHTML);
This allows me to dynamically write a coldfusion template to the page via javascript.
No Comments
Be the first to comment!