471,316 Members | 1,056 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

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

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 19 '05 #1
2 2384
If you look at the documentation for String.Replace()
[http://msdn.microsoft.com/library/de...acetopic2.asp]
you'll see that it the return value of the method is "A string equivalent to
this instance but with all instances of oldValue replaced with newValue."
In other words, the method does not change the original string, it returns
the string with the replacements. When you use it with your databinding
code, the runtime is rendering the output of the replace method.

You'll need to store the results of the method somewhere if you intend to
use them (write them to a database):
s = s.Replace(...)
or
s = MyTextbox.Text.Replace(...)

HTH
----------------
Dave Fancher
http://www.davefancher.com

"Winshent" <wi*************@yahoo.co.uk> wrote in message
news:11**********************@g49g2000cwa.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 19 '05 #2
acknowledged..

i was having one of those days !!

thanks.

Nov 19 '05 #3

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 rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.