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

SQL Text Field to HTML Paragraphs

Status
Not open for further replies.

anonim1

Programmer
Dec 10, 2004
108
US
I have an SQL table which has a field of type Text. The data that I store in the field contains line breaks to designate different paragraphs. If I run a SELECT statement using Query Analyzer, I see that the line breaks are preserved.

What I want to be able to do is insert <p></p> tags for each separate paragraph as I read through the field. What is the best way to do this? I am reading in the fields using an ASP.NET web application.
 
You would need to replace CRLF pairs with the <p> tag string. In classic ASP you would do something like this:

Code:
Response.Write "<p>" & Replace(text_field, Chr(13) & Chr(10), "</p><p>") & "</p>"

Another way is to just use line breaks:

Code:
Response.Write Replace(text_field, Chr(13) & Chr(10), "<br />")

NB: depending on where these text values are being generated from, you may find you only have CRs - Chr(13) - or LFs - Chr(10) - in your data. Normally you would have a pair as per my queries.

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top