Groups | Blog | Home
all groups > asp.net > february 2008 >

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


Alun
2/16/2008 8:53:06 PM
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
Masudur
2/17/2008 2:55:36 AM
[quoted text, click to view]

Hi...

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

Thanks
Masudur
Alexey Smirnov
2/17/2008 3:45:34 AM
[quoted text, click to view]

For me it works. Do you parse the code again somewhere before it's
Masudur
2/17/2008 9:52:00 PM
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
AddThis Social Bookmark Button