By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,069 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,069 IT Pros & Developers. It's quick & easy.

Displaying carriage returns in a memo field

P: n/a
Can someone please help with a suggestion as to how I can keep the
formatting (carriage returns) that the user enters into a memo field
and then display that later.

I figured I might be able to use:
'replace carriage returns with BRs
comment=Replace(comment, chr(13), "<br>")
but obviously net.!

The <pre> tag doesn't sem to help either as the embedded return is
lost by the time you get past Request.Form......

thanks

.les.
Aug 26 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I've never had a problem using Replace(), but I use chr(10) or vbCrLf, not
chr(13). I also only doing this when *displaying* the data, not when
storing it. I'm not sure why you think "the embedded return is lost"
because it is not. Could you show some sample code that reproduces this
problem?

http://www.aspfaq.com/2188

A
"Les Juby" <le*****@anti-spam.iafrica.com> wrote in message
news:43***************@news.telkomsa.net...
Can someone please help with a suggestion as to how I can keep the
formatting (carriage returns) that the user enters into a memo field
and then display that later.

I figured I might be able to use:
'replace carriage returns with BRs
comment=Replace(comment, chr(13), "<br>")
but obviously net.!

The <pre> tag doesn't sem to help either as the embedded return is
lost by the time you get past Request.Form......

thanks

.les.

Aug 26 '05 #2

P: n/a
Uuuuuuhh..... it was the chr(13) instead of chr(10)

A throwback to dBase and the old DOS days.

Works great, thanks for the help !

.les.
On Fri, 26 Aug 2005 16:15:18 -0400, "Aaron Bertrand [SQL Server MVP]"
<te*****@dnartreb.noraa> wrote:
I've never had a problem using Replace(), but I use chr(10) or vbCrLf, not
chr(13). I also only doing this when *displaying* the data, not when
storing it. I'm not sure why you think "the embedded return is lost"
because it is not. Could you show some sample code that reproduces this
problem?

http://www.aspfaq.com/2188

A
"Les Juby" <le*****@anti-spam.iafrica.com> wrote in message
news:43***************@news.telkomsa.net...
Can someone please help with a suggestion as to how I can keep the
formatting (carriage returns) that the user enters into a memo field
and then display that later.

I figured I might be able to use:
'replace carriage returns with BRs
comment=Replace(comment, chr(13), "<br>")
but obviously net.!

The <pre> tag doesn't sem to help either as the embedded return is
lost by the time you get past Request.Form......

thanks

.les.


Aug 26 '05 #3

P: n/a
Aaron Bertrand [SQL Server MVP] wrote:
I've never had a problem using Replace(), but I use chr(10)
or vbCrLf, not chr(13). I also only doing this when
*displaying* the data, not when storing it. I'm not sure why
you think "the embedded return is lost" because it is not.
Could you show some sample code that reproduces this problem?


Since the OP did not elaborate, I would like to offer this observation:
*Leading* carriage returns are not rendered by some browsers[1], meaning
they must be accounted for in post-back situations.

In other words, if you have something like this...

<textarea name="txt"><%=Request.Form("txt").Item%></textarea>

....and type the equivalent of "\r\nTest\r\n" (or: vbCrLf & "Test" & vbCrLf),
then the resulting HTML source is...

<textarea name="txt">
Test
</textarea>

....which is rendered in the browser identically to this:

<textarea name="txt">Test
</textarea>

Note that the carriage return was not lost in the form submission, as the
resultant HTML source properly contains it. Furthermore, the *trailing*
carriage returns are retained. It is an oddity, but not the only one.
Displaying the text outside the form control is a whole other animal.

Consider what happens when the following are added to my example:

<style type="text/css">
div { border:solid 1px #ccc; white-space:pre; }
pre { border:solid 1px #ccc; }
</style>
<div><%=Server.HTMLEncode(Request.Form("txt").Item )%></div>
<pre><%=Server.HTMLEncode(Request.Form("txt").Item )%></pre>
<div><%=Request.Form("txt").Item%></div>
<pre><%=Request.Form("txt").Item%></pre>

In all tested browsers, neither leading nor trailing carriage returns are
rendered <pre> in here </pre>. IE treats <div style="white-space:pre;">
identically. Opera and Firefox retain the leading carriage returns, but lost
the trailing ones. In all three browsers, the "white-space:pre" rendering
conflicts with that of <textarea>. It's no wonder the OP might think his
carriage returns are being lost.

[1] IE and Firefox, at a minimum. Opera does not lose them. UAs tested:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; en) Opera 8.01
Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.7.10) Gecko/20050716
Firefox/1.0.6
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322;
..NET CLR 1.0.3705; .NET CLR 2.0.40607)

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Aug 26 '05 #4

P: n/a
Here's what has worked for me although I usually put it into a function:

' Convert all vbCrLf to <br>.
' (This is the same as converting Chr(13) & Chr(10) to <br>.)
varFld = Replace(varFld, vbCrLf, "<br>")

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...

<<
Can someone please help with a suggestion as to how I can keep the
formatting (carriage returns) that the user enters into a memo field
and then display that later.

I figured I might be able to use:
'replace carriage returns with BRs
comment=Replace(comment, chr(13), "<br>")
but obviously net.!

The <pre> tag doesn't sem to help either as the embedded return is
lost by the time you get past Request.Form......


*** Sent via Developersdex http://www.developersdex.com ***
Aug 30 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.