Replace /n with a XHTML <br /> using string.replace

Discussion in 'ASP .Net' started by Alun, Feb 17, 2008.

  1. Alun

    Alun Guest

    I need to replace all new line characters in a string with a valid
    XHTML line break tag <br />.

    I'm trying to use the string.Replace method for this. Here's some
    example code:

    String description = "This is a video description \n Hello World";
    description = description.Replace("\n", "<br />");
    Literal1.Text = description;

    When run the Literal controls rendered HTML is:

    This is a video description <br> Hello World

    I'm expecting it to be:

    This is a video description <br /> Hello World

    Many thanks
    Alun
     
    Alun, Feb 17, 2008
    #1
    1. Advertising

  2. Alun

    Masudur Guest

    On Feb 17, 10:53 am, Alun <> wrote:
    > I need to replace all new line characters in a string with a valid
    > XHTML line break tag <br />.
    >
    > I'm trying to use the string.Replace method for this. Here's some
    > example code:
    >
    > String description = "This is a video description \n Hello World";
    > description = description.Replace("\n", "<br />");
    > Literal1.Text = description;
    >
    > When run the Literal controls rendered HTML is:
    >
    > This is a video description <br> Hello World
    >
    > I'm expecting it to be:
    >
    > This is a video description <br /> Hello World
    >
    > Many thanks
    > Alun


    Hi...

    try environment.newline in place of "<br/>"

    Thanks
    Masudur
    www.munna.shatkotha.com
     
    Masudur, Feb 17, 2008
    #2
    1. Advertising

  3. On Feb 17, 5:53 am, Alun <> wrote:
    > I need to replace all new line characters in a string with a valid
    > XHTML line break tag <br />.
    >
    > I'm trying to use the string.Replace method for this.  Here's some
    > example code:
    >
    > String description = "This is a video description \n Hello World";
    > description = description.Replace("\n", "<br />");
    > Literal1.Text = description;
    >
    > When run the Literal controls rendered HTML is:
    >
    > This is a video description <br> Hello World
    >
    > I'm expecting it to be:
    >
    > This is a video description <br /> Hello World


    For me it works. Do you parse the code again somewhere before it's
    rendered?
     
    Alexey Smirnov, Feb 17, 2008
    #3
  4. Alun

    Masudur Guest

    Hi...

    I tested the your code... that is

    "String description = "This is a video description \n Hello World";
    description = description.Replace("\n", "<br />");
    Literal1.Text = description; "

    worked okay.,...

    so need to use any environment.newline...

    i think the problem is some where else... and i guess with html
    encoding...

    did you changed any thing on on redner or on prerender

    Thanks
    Masudur
    www.munna.shatkotha.com
     
    Masudur, Feb 18, 2008
    #4
    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. Replies:
    7
    Views:
    909
  2. chronos3d
    Replies:
    9
    Views:
    804
    Andy Dingley
    Dec 5, 2006
  3. Usha2009
    Replies:
    0
    Views:
    1,147
    Usha2009
    Dec 20, 2009
  4. xhtml champs
    Replies:
    0
    Views:
    543
    xhtml champs
    Aug 1, 2011
  5. xhtml champs
    Replies:
    0
    Views:
    1,057
    xhtml champs
    Aug 2, 2011
Loading...

Share This Page