Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > preserving carriage returns

Reply
Thread Tools

preserving carriage returns

 
 
TheDude5B
Guest
Posts: n/a
 
      11-01-2005
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; ?

 
Reply With Quote
 
 
 
 
Mr Newbie
Guest
Posts: n/a
 
      11-01-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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; ?
>



 
Reply With Quote
 
 
 
 
Greg Burns
Guest
Posts: n/a
 
      11-01-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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; ?
>



 
Reply With Quote
 
TheDude5B
Guest
Posts: n/a
 
      11-01-2005
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

 
Reply With Quote
 
Greg Burns
Guest
Posts: n/a
 
      11-01-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
TheDude5B
Guest
Posts: n/a
 
      11-01-2005
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?

 
Reply With Quote
 
TheDude5B
Guest
Posts: n/a
 
      11-01-2005
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

 
Reply With Quote
 
Greg Burns
Guest
Posts: n/a
 
      11-01-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
sp3d2orbit
Guest
Posts: n/a
 
      11-02-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sign preserving Vs value preserving sophia.agnes@gmail.com C Programming 4 12-07-2007 03:14 PM
integral promotion, arithmetic conversion, value preserving, unsigned preserving??? TTroy C Programming 16 01-31-2005 10:20 PM
Help: Delete a single carriage return in a file, but not a double carriage return? Steve Anderson Perl Misc 3 06-21-2004 12:48 AM
Preserving Carriage Return in a Web service Wesley C ASP .Net Web Services 2 01-08-2004 03:44 PM
Carriage Returns and sockets Iceberg Perl 1 09-06-2003 04:49 PM



Advertisments