By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,606 Members | 3,802 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,606 IT Pros & Developers. It's quick & easy.

preserving carriage returns

P: n/a
Hi,

I have some data which is stored in my MySQL database as TEXT. when the
data is entered in, it has some carriage returns in it, and this can be
seen when querying the data using MySQL Query Browser.

I want to then display this text within <p> tags when requested from
the database. However, the test is formatted without the carriage
returns.

Is there a simple bit of code in which i can use to display the text
complete with its carriage returns, or do i have to have a bit of messy
code which will replace all the carriage returns with &vbCrLF; ?

Nov 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
You need to replace the CR's with <P> or <BR> 's in order to translate them
to HTML actionable code tags.

Use a RegEx to do this.

Regards Mr Newbie.
"TheDude5B" <ti*******@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi,

I have some data which is stored in my MySQL database as TEXT. when the
data is entered in, it has some carriage returns in it, and this can be
seen when querying the data using MySQL Query Browser.

I want to then display this text within <p> tags when requested from
the database. However, the test is formatted without the carriage
returns.

Is there a simple bit of code in which i can use to display the text
complete with its carriage returns, or do i have to have a bit of messy
code which will replace all the carriage returns with &vbCrLF; ?

Nov 19 '05 #2

P: n/a
I would think you would have to replace the carriage returns with <br>'s.

Dim TestString As String = "Shopping List"
' Returns "Shipping List".
Dim aString As String = Replace(TestString, "o", "i")

Greg

"TheDude5B" <ti*******@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi,

I have some data which is stored in my MySQL database as TEXT. when the
data is entered in, it has some carriage returns in it, and this can be
seen when querying the data using MySQL Query Browser.

I want to then display this text within <p> tags when requested from
the database. However, the test is formatted without the carriage
returns.

Is there a simple bit of code in which i can use to display the text
complete with its carriage returns, or do i have to have a bit of messy
code which will replace all the carriage returns with &vbCrLF; ?

Nov 19 '05 #3

P: n/a
I have used
Replace(post.Text, vbCrLf, "<br />")

and everything is working now, however, this is good for displaying my
text within the <p> tags. but when i view the text within a textbox,
for example when i want to edit the text, it shows up the <br /> tags

Nov 19 '05 #4

P: n/a
Only do the replace when displaying the text in a label. Should give some
thought to using Server.HtmlEncode too.

Replace(Server.HtmlEncode(post.Text), vbCrLf, "<br />")

"TheDude5B" <ti*******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I have used
Replace(post.Text, vbCrLf, "<br />")

and everything is working now, however, this is good for displaying my
text within the <p> tags. but when i view the text within a textbox,
for example when i want to edit the text, it shows up the <br /> tags

Nov 19 '05 #5

P: n/a
ok i will not replace the vbcrlf when adding it to the database.
however i am unsure as to apply the replace code with my asp:repeater
controls.

i have the code for the line, which i am wanting to use the replace in,
as

<td colspan="2"
class="bordersides"><p><%#Container.DataItem("post _text")%></p></td>

how would i apply Replace( ,vbCrLf,"<br />") with this line
of code?

Nov 19 '05 #6

P: n/a
i have got it now thanks.

used the code

<%#( DataBinder.Eval(Container.DataItem, "post_text")).Replace(vbCrLf,
"<br/>")%>

and this has worked.

Thanks for your Help Greg

Nov 19 '05 #7

P: n/a
Another method would be to write a protected helper function in your code
behind.

something like this:

<%# MyHelperFunction(DataBinder.Eval(Container.DataIte m, "post_text")))%>

Protected Function MyHelperFunction(ByVal value As Object) As String
If value Is DBNull.Value Then
Return ""
Else
Return value.ToString.Replace(vbCrLf,"<br/>")
End If
End Function

I find this kind of code necessary to protected myself from NULL values
coming back from db.

Greg

"TheDude5B" <ti*******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
i have got it now thanks.

used the code

<%#( DataBinder.Eval(Container.DataItem, "post_text")).Replace(vbCrLf,
"<br/>")%>

and this has worked.

Thanks for your Help Greg

Nov 19 '05 #8

P: n/a
Instead of doing a replace, a css attribute exists that you can use to
format the text automatically:

<div style="white-space: pre-line;">
Text goes here
</div>

Lookup the "white-space" css attribute for more info.

Best of luck,
Matt Furnari

Nov 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.