Unicode to HTML converter/cleaner

  • Thread starter Thread starter Rob
  • Start date Start date
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.
 
I suppose you need to smth like System.Text.Encoding.Convert and
HttpServerUtility.HtmlEncode methods

Btw, all strings in .NET are unicode ones
 
I suppose you need to smth like System.Text.Encoding.Convert and
HttpServerUtility.HtmlEncode methods

Btw, all strings in .NET are unicode ones
 
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.
 
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.
 
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.
 
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...
 
Back
Top