Try using stripCR():

<cfif isdefined("FORM.txtArea")>
        <cfoutput>
                <pre>#stripCR(FORM.txtArea)#</pre>
        </cfoutput>
</cfif>


<cfparam name="FORM.txtArea" default="">

<cfoutput>
        <form action="#CGI.SCRIPT_NAME#" METHOD="POST">
                <textarea name="txtArea">#FORM.txtArea#</textarea>
                <input type=submit>
        </form>
</cfoutput>

-----Original Message-----
From: Douglas Malcolm [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 14, 2001 11:35 AM
To: CF-Talk
Subject: Extra carriage returns when writing file?


Background:
My company uses a javascript file to create faux-banners (really a
banner-sized table) that have form elements tying into our articles
database.  The point is to allow others to simply include the js file in
their html, and be able to offer searches against our articles.

Simple, right?  Yes.  An added wrinkle is that we use a content management
system that allows our editors to modify the various categories articles can
be filed under.  The faux-banner uses a dropdown select list of our
categories.

Since the categories change rather infrequently, the js files are hard coded
with our categories list, and I've written a cf file that will trip when a
category change is made.  This file reads in the old js file, uses RegExp to
replace the old category list with the new one, then writes out the new js
file over the old one.

The Weirdness:
It all works fine, if a bit clumsily (something about using 2 <cffile>'s,
one to delete the old file, and another to write the new strikes me as
inelegant - I'm open to ideas on that).

The trouble is that ~something~ is adding extra hard returns in between the
lines of code I am not modifying.  Example:

Original file:
line of code
line of code
line I'm changing
line I'm changing
line of code
line of code
----------------------------------------
After first time through:
line of code

line of code

line I'm changing
line I'm changing

line of code

line of code

---------------------------------------
After second time through:
line of code


line of code


line I'm changing
line I'm changing


line of code


line of code
---------------------------------------

What is going on here?  I must be doing something wrong, but damned if I can
spot it.  Here is the code that does the processing.  Any help would be
appreciated.  I mean, technically it works now, but it sure is ugly.

---------------------------------------

<cfquery datasource="articles" name="allcats">
        SELECT * FROM categories
        ORDER BY cgyname
</cfquery>


<CFSET cr='
'>
<cfset abpath = "[removed for posting]">

<cflock timeout=15>

<!--- Wrap javascript around the form Select code --->
<CFSET currentcats="">
<CFSET currentcats="<!-- start dynamic -->" & cr>
<CFLOOP QUERY="allcats">
        <CFSET currentcats=currentcats &
"document.write('<OPTION>#cgyname#');" &
cr>
</CFLOOP>
<CFSET currentcats=currentcats & "<!-- end dynamic -->" & cr>

<!--- Read in the Search.js file, and replace old category list with
new --->
<cffile action="read" file="#abpath#\Search.js" variable="oldjsfile">
<cfset newjsfile=#REReplaceNoCase(oldjsfile,'<!--
start([[:alpha:]]|[[:space:]]|[[:punct:]])+end
dynamic -->','#currentcats#')#>

<!--- Delete the old file --->
<cffile action="delete" file="#abpath#\Search.js">

<!--- and write the new one --->
<cffile action="write" file="#abpath#\Search.js" output="#newjsfile#">

</cflock>

---------------------------------------


Thank you!

Douglas Malcolm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to