striping text of special characters before displaying on webpage

E

ebade2000

I have this project I am working and I have two tasks

I have a text form that takes in a users input and it is supposed to be
stored in a database and can be viewed from a webpage. I want to be
able to display the text with html special characters like "<", ">" (if
the user typed them in) without it being confused for html code and...

I want to be able to replace a newline character with a "/r/n" whenever
it is used in the text.
 
M

Morten Wennevik

Hi ebade2000,

String.Replace and Server.HtmlEncode should do the trick.

string s = "<display \r\n me>";
s = Server.HtmlEncode(s); // converts < > etc
s = s.Replace("\r\n", "<br>"); // replaces string breaks with html
breaks
Response.Write(s);
 
E

ebade2000

Thanks that helps a whole lot.

Bade

Morten said:
Hi ebade2000,

String.Replace and Server.HtmlEncode should do the trick.

string s = "<display \r\n me>";
s = Server.HtmlEncode(s); // converts < > etc
s = s.Replace("\r\n", "<br>"); // replaces string breaks with html
breaks
Response.Write(s);
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top