Forum Moderators: open

Message Too Old, No Replies

Need to read and display carriage return from DB

         

kevinj

6:53 pm on Apr 13, 2003 (gmt 0)

10+ Year Member



I have an admin section set up for a client that includes a text area where they can add text. The text is written to a database. On the display page I want the page to recognize the returns that the client hit when entering the text and to then display the returns similar to a <br> tag.

I tried to use a replace statement when getting the field but have had no luck with it:

ARCHIVE_EVENT = Replace(Info("archive_event"),Chr(13), Chr(10) & Chr(13))

Any help would be greatly appreciated.

defanjos

7:09 pm on Apr 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is what I do

Place on the <head> something like this:
<%
dim textarea
textarea = rs("textarea")

Function CR(string)
CR = Replace(string, vbcrlf,"<br>")
End Function
%>

Place on <body> this:

<%=cr(textarea)%>

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

hope it helps
I am sure there are easier ways to do it, but this one has worked for me.

sullen

7:14 pm on Apr 13, 2003 (gmt 0)

10+ Year Member



I'm not quite sure what you're trying to do here. The newline character is Chr(13) and Chr(10) (sorry, can't remember which order they go in) - so you're trying to replace one part of the new line with both?

Anyway, I usually use this:

ARCHIVE_EVENT = Replace(Info("archive_event"),Chr(10), "<br>")

Since Chr(10) is the part of the newline that always appears, even if the text has been copied and pasted from a dodgy Word-processor (you can just ignore the Chr(13)). NB I can't actually find an example of this so I could have them the wrong way round - it could be Chr(13) you need to use, you'll have to test it. I usually just use vbnewline for readablity anyway (but this fails with the dodgy pasted text)

Also this code can fail if the field is null, so I always use a standalone function which tests whther or not the field is null first.

Hope that makes sense.

sullen

7:15 pm on Apr 13, 2003 (gmt 0)

10+ Year Member



hmm defanjos beat me.

I would add the line

if textarea<>"" and not isnull(string) to that function.

kevinj

7:31 pm on Apr 13, 2003 (gmt 0)

10+ Year Member



Thanks for the help guys. I couldn't get the replace function to work, so I ended up using the function defanjos listed. Really appreciate both your help. Now back to watching the Masters.

BradleyT

7:32 pm on Apr 13, 2003 (gmt 0)

10+ Year Member



strComments = rs("COMMENTS")

IF strComments <> "" THEN
strComments = Replace(strComments, vbCrLf, "<br>")
END IF

If you don't check for "" then you get an error on your replace if the field is empty.

And since you're manipulating the field a few times it's better to put the field into a holder and then manipulate the holder rather than accessing rs("COMMENTS") several times.