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

  • Thread starter Thread starter Alun
  • Start date Start date
A

Alun

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
 
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
 
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?
 
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
 
Back
Top