Unicode to HTML converter/cleaner

R

Rob

Is there a handy .NET call to convert a Unicode string to valid HTML so
sticking in an <p> inner HTML? Kind of thing converts "<" to &lt and
multiple spaces to &nbsp etc. I need to display unicode text from a database
on the web page.

Cheers, Rob.
 
G

Guest

I suppose you need to smth like System.Text.Encoding.Convert and
HttpServerUtility.HtmlEncode methods

Btw, all strings in .NET are unicode ones
 
G

Guest

I suppose you need to smth like System.Text.Encoding.Convert and
HttpServerUtility.HtmlEncode methods

Btw, all strings in .NET are unicode ones
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

Rob said:
Is there a handy .NET call to convert a Unicode string to valid HTML so
sticking in an <p> inner HTML? Kind of thing converts "<" to &lt and
multiple spaces to &nbsp etc. I need to display unicode text from a database
on the web page.

The Server.HtmlEncode method will encode special characters like &<>"
into html entities. It will not do anything to line breaks, tabs or
multiple spaces, though, so you have to replace them yourself.
 
R

Rob

The Server.HtmlEncode method will encode special characters like & said:
html entities. It will not do anything to line breaks, tabs or multiple
spaces, though, so you have to replace them yourself.

Thanks, I'll check them out. Not too difficult to Replace(Text, vbcrlf,
"<br>") afterwards. BTW, should I be doing "<br/>" these days?

Cheers, Rob.
 
R

Rob

At the risk of extreme pedantry, it's <br />, not <br/>

Yes I'd read that somewhere but then seen many places where the space was
been dropped.

Such as internet standards :)

Cheers, Rob.
 
M

Mark Rae [MVP]

Yes I'd read that somewhere but then seen many places where the space was
been dropped.

Of course you have - the Internet is littered with badly-formed markup...
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top