Carriage Return and Response.Write Output Issue

C

crjunk

I have a field in a SQL Server table named DetailedDescription that is
a varchar. If the user adds/edits a detailed description, they do so
in a MulltiLine TextBox control. Therefore, they are able to click
enter on their keyboard and have multiple carriage returns inside the
DetaildDescription.

My problem is that I have another webpage in my project that has the
following statement in it:
Response.Write(drSQL.Item("DetailDescription")).

If the user created a record in the following format:
HELLO
WORLD

It is now displayed as:
HELLO WORLD

Is there something I can add to my Response.Write statement so that the
carriage returns are "written" so that the output is in the following
format:
HELLO
WORLD

I hope this makes sense.


Thanks,
CR Junk
 
B

Bob Barrows [MVP]

crjunk said:
I have a field in a SQL Server table named DetailedDescription that is
a varchar. If the user adds/edits a detailed description, they do
so in a MulltiLine TextBox control. Therefore, they are able to
click enter on their keyboard and have multiple carriage returns
inside the DetaildDescription.

My problem is that I have another webpage in my project that has the
following statement in it:
Response.Write(drSQL.Item("DetailDescription")).

If the user created a record in the following format:
HELLO
WORLD

It is now displayed as:
HELLO WORLD

Is there something I can add to my Response.Write statement so that
the carriage returns are "written" so that the output is in the
following format:
HELLO
WORLD
A. Display the data in a textarea instead of response.writing it into
the html
B. Surround the data in <PRE></PRE> tags
C. Replace the carriage returns with <BR> - this is basic html.
 
F

Firas

Hi, if i were you, i would use the same as Gomer's but with little
modification
Response.Write(replace(drSQL.Item("DetailDescription"),chr(13),"<BR>")

what i did is that i replaced the vbCrLf to chr(13), because the vbCrLf
is combination of chr(13) and chr(10), so what if the user had used a
format that he only included the chr(13), then if you use the vbCrLf it
will not work, because using the vbCrlf will look for the two at once
which only one is available. And by the way, according to me testings,
chr(13) is required for the enter more than the chr(10) which means
chr(10) is always to occure.
And if you still want to use his advice, then use it this way: use vbCr
instead of chr(13)


Best Regards
Firas S Assaad
 
A

Anthony Jones

Firas said:
Hi, if i were you, i would use the same as Gomer's but with little
modification
Response.Write(replace(drSQL.Item("DetailDescription"),chr(13),"<BR>")

what i did is that i replaced the vbCrLf to chr(13), because the vbCrLf
is combination of chr(13) and chr(10), so what if the user had used a
format that he only included the chr(13), then if you use the vbCrLf it
will not work, because using the vbCrlf will look for the two at once
which only one is available. And by the way, according to me testings,
chr(13) is required for the enter more than the chr(10) which means
chr(10) is always to occure.
And if you still want to use his advice, then use it this way: use vbCr
instead of chr(13)

There are two end-of-line markers in common use. CRLF or just plain LF.
I've not come across many (in fact never have) systems that only use CR.
What tests did you use to discover that CR on it's own is more common or
indeed ever happens at all?

My solution BTW is :-

Replace(Replace(Server.HTMLEncode(s), vbCR, ""), vbLF, "<br />")
 
X

XML noob

we're talking about someone hitting the enter key in text area on a web
page...
how would this ever be translated into anything other than crlf??
 
B

Bob Barrows [MVP]

I think that's exactly Anthony's question. Perhaps Firas is aware of a
browser that will use vbCr instead of vbCrLf.
 
A

Anthony Jones

XML noob said:
we're talking about someone hitting the enter key in text area on a web
page...
how would this ever be translated into anything other than crlf??

If you pass stuff around via XML you will find CRLFs being converted to just
LFs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top