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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alun

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

    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.Rep lace("\n", "<br />");
    Literal1.Text = description;

    When run the Literal controls rendered HTML is:

    This is a video description <brHello World

    I'm expecting it to be:

    This is a video description <br /Hello World

    Many thanks
    Alun
  • Masudur

    #2
    Re: Replace /n with a XHTML &lt;br /&gt; using string.replace

    On Feb 17, 10:53 am, Alun <alu...@gmail.c omwrote:
    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.Rep lace("\n", "<br />");
    Literal1.Text = description;
    >
    When run the Literal controls rendered HTML is:
    >
    This is a video description <brHello World
    >
    I'm expecting it to be:
    >
    This is a video description <br /Hello World
    >
    Many thanks
    Alun
    Hi...

    try environment.new line in place of "<br/>"

    Thanks
    Masudur

    Comment

    • Alexey Smirnov

      #3
      Re: Replace /n with a XHTML &lt;br /&gt; using string.replace

      On Feb 17, 5:53 am, Alun <alu...@gmail.c omwrote:
      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.Rep lace("\n", "<br />");
      Literal1.Text = description;
      >
      When run the Literal controls rendered HTML is:
      >
      This is a video description <brHello 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?

      Comment

      • Masudur

        #4
        Re: Replace /n with a XHTML &lt;br /&gt; using string.replace

        Hi...

        I tested the your code... that is

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

        worked okay.,...

        so need to use any environment.new line...

        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


        Comment

        Working...