Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Active Server Pages (ASP)
Expertise: Beginner
Feb 25, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Present Data From TEXT Field With Line Breaks


I have data (text + CR + LF) stored in SQL Server 6.5 as a TEXT data type. When I want to display the data on an ASP page, the text loses its format. If I use TEXT INPUT on my ASP, it works fine but I need to scroll up and down to see the data, which is okay, but when I print, not all the data gets printed.

Do you have a workaround for this problem? I am trying to reduce the maintenance of one of our sites, which has hundreds of similar HTML pages that could be generated by one ASP page.


The data is being presented correctly within your ASP/HTML page. If you choose to View Source, you will see that all your line breaks CR+LFs are being retained. However, one of the rules of HTML rendering is that it ignores extra white space. So your line breaks are being ignored. Therefore, you are losing the format.

To fix this problem, before you write the data out to the browser (using a Response.write), replace all occurrences of the CR+LF with the HTML equivalent,
. Assuming strText contains the value you want to write to the browser, use the code:

Response.write Replace(strText, vbCrLf, "

The vbCrLf is a built-in constant for the CR+LF characters.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date