Sunday, May 29, 2005

Stripping Text from Strings With Coldfusion

I am attempting to delete a string from a file using <CFFILE> and Replace(). It works fine except that there is a gaping "hole" left in my string where the string should close up.

<!--- Open File --->
<cffile action="read" file="/mypath/myfile.txt" variable="myfile_Original">

<!--- Replace Changed String --->
<cfset myfile_Updated = Replace(myfile_Original, "Delete this line of text please!", "")>

<!--- Write Changed File --->
<cffile action="write" file="/mypath/myfile.txt"
output="#myfile_Updated#" addnewline="no">

How can I delete a string of words in a file without having it leaving any space, CRLF etc. ?

Replace duplicate CRLF's with a single CRLF.

<CFSET cr=Chr(13) & Chr(10)>
<CFSET Txt=Replace(Txt,cr & cr,cr,"ALL")>

0 Comments:

Post a Comment

<< Home