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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing line breaks with <br> 1

Status
Not open for further replies.

sevex

Programmer
Sep 18, 2001
74
CA
I have a piece of multiline text. I'm trying to replace the line breaks with:

<cfset address = Replace(address, &quot;#chr(13)##chr(10)#&quot;, &quot;<br>&quot; , &quot;all&quot;)>

<cfoutput>#address#</cfoutput>

But it doesn't seem to find the line breaks. ParagaphFormat doesn't work either, and puts an ugly large amount of extra space below the text.

Anyone have any suggestions?
 
Hey Sevex,

Your code looks correct although I would suggest removing the #chr(13)# as this is only present in Windows text. If the text came from a Unix based system, the line breaks are represented by a single #chr(10)# and your replace won't match.

This should work the way you want as I just tested it.

<cfset address = Replace(address, #chr(10)#, &quot;<br>&quot; ,&quot;all&quot;)>

Let me know if this doesn't work,
GJ
 
Thanks but that didn't work for me. Input is coming from a windows machine in this situation.

In the html source the address is displaying on three separate lines like it should... this is so frustrating :p
 
Do you show <br> tags at all in the source? I'm guessing not as it sounds like the line breaks are remaining which would cause the text to be displayed on separate lines in &quot;view source&quot;.

Paste this code just above the replace function and let me know what you see.

#find(chr(10),address)#

This function should output either 0 or some positive number to indicate where it found the linebreak character. It looks like it's not finding the linebreak character for some reason and I want to verify it's actually in your text string.

GJ
 
it displays &quot;20&quot; which appears to be correct, as that's where the first linebreak should be.
 
You didn't say but I assume there are no &quot;<br>&quot;s in the code when you do a view source. If this is the case, then it appears the breaks are in the text and CF can find them but the replace isn't really replacing them. I would make certain you don't have the variable misspelled in the <cfset > statement.

Try this code and let me know what you see between the two horizontal rules. Also, let me know what you see inside &quot;view source&quot;. (put this before the <cfset > line)

<hr>
<cfoutput>#Replace(address, #chr(10)#, &quot;<br>&quot; ,&quot;all&quot;)#</cfoutput>
<hr>

GJ

 
that worked like a charm! thanks!

I'm guessing it had something to do with the fact that I was outputting a query? maybe when I set &quot;address&quot; to the new replaced address, it would still just output the original query address. whatever, it works. Thanks again for all your help.
 
If &quot;address&quot; is just a variable and not a query, I would have expected your original code to work. If address is part of a query, that might explain your problem. I've never tried to change a query variable but my suspicion is it wouldn't work. Anyway, if it works now, that's good enough for me :)

Good luck,
GJ
 
I was calling it from within a <cfoutput query=&quot;whatever&quot;> so maybe I had to assign it <cfset whatever.address = &quot;replacedstuff&quot;>

If I ever run into it again I'll try it, but for now, I just don't care!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top