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

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
 
M

Masudur

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
 
G

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

For me it works. Do you parse the code again somewhere before it's
rendered?
 
M

Masudur

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,844
Latest member
JudyGvh32

Latest Threads

Top