Convert from Entity Reference to Hex or Decimal?

K

kurt

hello,
Is there a way to convert entity references ( "ã",etc)
to their equivalent hex or decimal codes without using an associative
array or some such thing to list all the equivalencies?
thanks,
kurt
 
F

Fox

kurt said:
hello,
Is there a way to convert entity references ( "ã",etc)
to their equivalent hex or decimal codes without using an associative
array or some such thing to list all the equivalencies?
thanks,
kurt

These might work:

var gDiv = null;

function
entity2CharCode(ent)
{
var retval = null;

if(!gDiv)
gDiv = document.createElement('DIV');

gDiv.innerHTML = ent;

return gDiv.innerHTML.charCodeAt(0);
}

function
entity2Hex(ent)
{

if(!gDiv)
gDiv = document.createElement('DIV');

gDiv.innerHTML = ent;

return gDiv.innerHTML.charCodeAt(0).toString(16).toUpperCase();
}

alert("ã = &#" + entity2CharCode("ã"));
alert("ð = %" + entity2Hex("ð") +
" (" + entity2CharCode("ð") + ")");


You should implement error checking...

Fox
***************
 
K

kurt

These might work:

var gDiv = null;

function
entity2CharCode(ent)
{
var retval = null;

if(!gDiv)
gDiv = document.createElement('DIV');

gDiv.innerHTML = ent;

return gDiv.innerHTML.charCodeAt(0);
}

function
entity2Hex(ent)
{

if(!gDiv)
gDiv = document.createElement('DIV');

gDiv.innerHTML = ent;

return gDiv.innerHTML.charCodeAt(0).toString(16).toUpperCase();
}

alert("ã = &#" + entity2CharCode("ã"));
alert("ð = %" + entity2Hex("ð") +
" (" + entity2CharCode("ð") + ")");


You should implement error checking...

Fox
***************


works great! (mozilla, IE; on XP) thanks!
 

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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top