469,623 Members | 1,003 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

Store Carriage Returns as <br /><br /> or <p></p> in DB

I have a multi line text in an admin page on my cms.

I am trying to capture carriage returns as and replace them with
<p></p> bfore the string gets written to the database.

I have tried all the charcontrols option and chr(13) with success.. was
using the following code:

Dim s As String = MyTextbox.Text

s = "<p>" & s & "</p>"
s.Replace(ControlChars.CrLf & ControlChars.CrLf, "</p><p>")
s.Replace(ControlChars.Lf, "<br />")
s.Replace("\n", "<br />")
s.Replace(ControlChars.Cr & ControlChars.Cr, "</p><p>")
s.Replace(ControlChars.NewLine, "<br />")
s.Replace(ControlChars.VerticalTab, "<br />")
s.Replace(Chr(13), "<br />")

I have tried all the above, but non have worked.

The only work around i have found is to perform a string.replace when
displaying on the webpage by the following:

<%# container.dataitem("MyTextField").replace(chr(13), "<br />") %>

This works but is not ideal as it means i have to hard code each page.

How do i do this?

Nov 21 '05 #1
1 2943
Hi,

String.Replace is a function that returns a string. Try this
instead.

s=s.Replace(ControlChars.CrLf & ControlChars.CrLf, "</p><p>")
Ken
-------------------
"Winshent" <wi*************@yahoo.co.uk> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I have a multi line text in an admin page on my cms.

I am trying to capture carriage returns as and replace them with
<p></p> bfore the string gets written to the database.

I have tried all the charcontrols option and chr(13) with success.. was
using the following code:

Dim s As String = MyTextbox.Text

s = "<p>" & s & "</p>"
s.Replace(ControlChars.CrLf & ControlChars.CrLf, "</p><p>")
s.Replace(ControlChars.Lf, "<br />")
s.Replace("\n", "<br />")
s.Replace(ControlChars.Cr & ControlChars.Cr, "</p><p>")
s.Replace(ControlChars.NewLine, "<br />")
s.Replace(ControlChars.VerticalTab, "<br />")
s.Replace(Chr(13), "<br />")

I have tried all the above, but non have worked.

The only work around i have found is to perform a string.replace when
displaying on the webpage by the following:

<%# container.dataitem("MyTextField").replace(chr(13), "<br />") %>

This works but is not ideal as it means i have to hard code each page.

How do i do this?

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by noor.rahman | last post: by
9 posts views Thread by Wayne | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.