Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFFile retrieves the file in one line!

Status
Not open for further replies.

Bikzit

Programmer
Mar 24, 2001
9
0
0
AE
Hi There ..
I was tryin' to read a text file usin' the tag CFFile as the followin':
<CFFile Action=&quot;read&quot; File=&quot;c:\T.txt&quot; Variable=&quot;var_t&quot;>

But when i tried to output the variable as the followin': <CFOutput>#var_t#</CFOutput> I got the contents of the file on one line, while the real contents of the file are:
Line 1
Line 2
Line 3
Line 4

I got them like this:
Line1Line2Line3Line4

How can i retrieve the contents as they are?
Can Ya Help Plz! <CFBikzit Text=&quot;Hi There&quot;>
 
I assume you're reading in a text file and trying to display it in a browser. With a text file, special characters called Carriage-Return & Line-Feed (ascii 13 & 10) tell the text editor where to separate the lines. In a web browser, the character sequences (html tags) &quot;<br>&quot; and &quot;<p>&quot; tell it where to separate lines.

What is happenning is that the browser is seeing &quot;line1#asci13##ascii10#line2...&quot; so it displays it as one line because there are no &quot;<br>&quot; or &quot;<p>&quot; tags. What you want to do is convert the ascii 10 characters to &quot;<br>&quot; tags and you should get the proper formatting. Since Unix files just use the Line-Feed (ascii 10) to designate line breaks, you'll want to search and replace just the ascii 10 characters since the 13,10 sequence will only be found in a windows text file.

Just use this:
<cfoutput>#replace(var_t,&quot;#chr(10)#&quot;,&quot;<br>&quot;,&quot;all&quot;)#</cfoutput>

Let me know if you still have trouble,
GJ
 
Hey Bikzit

You can save a little work by using ParagraphFormat(Text)
it does exactly what GunJack described in the above post.

 
Actually it doesn't. Paragraphformat() turns single CR,LF's into spaces instead of line breaks. If you want the format he outlined above where single line breaks are turned into <br> tags, you'll need to use the replace function or something similar.

GJ
 

My Bad GunJack paragraphformat has always worked for me ;)
 
HEY Guys I thought I would stick my foot in my mouth one more time.

I messed around with this for a while (basically because I hate being wrong) and GunJack's Replace did work better then my ParagraphFormat. However neither one preserved all of the text formatting. So I tried HTMLcodeFormat and although it just places <pre> </pre> tags around the text it actually preserved all of the formating and made for the most accurate browser view of the text.

So I hope we've answered Bikzit's question thoroughly.
 
Hehe, I know the feeling, I hate being wrong too :) If you really wanted to preserve all the formatting, I would nest that replace() statement in another replace() that changed all double spaces into a space +  . If you then nested that output inside one that changed all tab characters into &quot;      ...&quot;, I think you would have a pretty accurate translation without using the &quot;<pre>&quot; tags.

GJ
 
Ooops, some of my post didn't come through right. It should have been this

... another replace() that changed all double spaces into a space + &nbsp; . If you then nested that output inside one that changed all tab characters into &quot;&nbsp; &nbsp; &nbsp; ...&quot;, I think you would have a pretty accurate translation without using the &quot;<pre>&quot; tags.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top