preserving carriage returns

Discussion in 'ASP .Net' started by TheDude5B, Nov 1, 2005.

  1. TheDude5B

    TheDude5B Guest

    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; ?
     
    TheDude5B, Nov 1, 2005
    #1
    1. Advertising

  2. TheDude5B

    Mr Newbie Guest

    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" <> wrote in message
    news:...
    > 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; ?
    >
     
    Mr Newbie, Nov 1, 2005
    #2
    1. Advertising

  3. TheDude5B

    Greg Burns Guest

    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" <> wrote in message
    news:...
    > 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; ?
    >
     
    Greg Burns, Nov 1, 2005
    #3
  4. TheDude5B

    TheDude5B Guest

    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
     
    TheDude5B, Nov 1, 2005
    #4
  5. TheDude5B

    Greg Burns Guest

    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" <> wrote in message
    news:...
    >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
    >
     
    Greg Burns, Nov 1, 2005
    #5
  6. TheDude5B

    TheDude5B Guest

    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?
     
    TheDude5B, Nov 1, 2005
    #6
  7. TheDude5B

    TheDude5B Guest

    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
     
    TheDude5B, Nov 1, 2005
    #7
  8. TheDude5B

    Greg Burns Guest

    Another method would be to write a protected helper function in your code
    behind.

    something like this:

    <%# MyHelperFunction(DataBinder.Eval(Container.DataItem, "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" <> wrote in message
    news:...
    >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
    >
     
    Greg Burns, Nov 1, 2005
    #8
  9. TheDude5B

    sp3d2orbit Guest

    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
     
    sp3d2orbit, Nov 2, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Iceberg

    Carriage Returns and sockets

    Iceberg, Sep 6, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,166
    Iceberg
    Sep 6, 2003
  2. TTroy
    Replies:
    16
    Views:
    803
    Peter Nilsson
    Jan 31, 2005
  3. Replies:
    4
    Views:
    544
  4. Wesley C

    Preserving Carriage Return in a Web service

    Wesley C, Dec 16, 2003, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    413
    Alin Popovici
    Jan 8, 2004
  5. Steve Anderson
    Replies:
    3
    Views:
    265
    Steve Anderson
    Jun 21, 2004
Loading...

Share This Page