Convert latin-1 characters to named HTML entities?

J

Joergen Bech

Is there a function in the .Net 1.1 framework
that will take, say, a string containing Scandinavian
characters and output the corret HTML entities, such
as

æ
ø
å

etc.

I am currently using FreeTextBox, but while it seems to
convert some characters (<, >, ...), others are left alone
and need to be converted separately.

I cannot use Response.Write or similar: I am taking freeform
input from FreeTextBox and normal textboxes and creating
static HTML files for later use, using String.Replace.

Basically, I need something that will convert the first column
to the third in
http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/charset1.asp
but if there is already something in the framework for this purpose
I would feel silly writing my own (probably slower) function.

TIA,

Joergen Bech
 
J

Joerg Jooss

Joergen said:
Is there a function in the .Net 1.1 framework
that will take, say, a string containing Scandinavian
characters and output the corret HTML entities, such
as

&aelig;
&oslash;
&aring;

etc.

I am currently using FreeTextBox, but while it seems to
convert some characters (<, >, ...), others are left alone
and need to be converted separately.

I cannot use Response.Write or similar: I am taking freeform
input from FreeTextBox and normal textboxes and creating
static HTML files for later use, using String.Replace.

Basically, I need something that will convert the first column
to the third in
http://msdn.microsoft.com/workshop/author/dhtml/reference/charsets/cha
rset1.asp but if there is already something in the framework for this
purpose I would feel silly writing my own (probably slower) function.

Do you really need character references, or will numeric references
work for you as well (they should)?

System.Web.HttpUtility.HtmlEncode() and
System.Web.HttpServerUtility.HtmlEncode() (which calls the other one)
do that trick. You may find though that the encoded output uses both
character and numeric references (see http://tinyurl.com/9bq6g).

Cheers,
 
J

Joergen Bech

Do you really need character references, or will numeric references
work for you as well (they should)?

System.Web.HttpUtility.HtmlEncode() and
System.Web.HttpServerUtility.HtmlEncode() (which calls the other one)
do that trick. You may find though that the encoded output uses both
character and numeric references (see http://tinyurl.com/9bq6g).

Cheers,

Thanks. I'll try. Trouble is, I would like everything to be named
html entities (for other reasons). I'll have to use HTMLEncode if a
few custom string replacements turn out to insufficient.

Sure am surprised, though, that it seems so hard to find a
function for this purpose (in .Net). Something like:
http://maconlinux.net/linux-man-pages/en/HTML::Entities.3.html

The Microsoft.SharePoint.Utilities.SPEncode class sounds useful,
but not to me, as this is not a SharePoint application.

I'll have to investigate the possibilities later.

Regards,

Joergen Bech
 

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,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top