On Sat, 18 Sep 2004 04:00:42 -0500, Fox <> wrote:
>
>
>kurt wrote:
>> 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).toUpperC ase();
>}
>
>alert("ã = &#" + entity2CharCode("ã"));
>alert("ð = %" + entity2Hex("ð") +
> " (" + entity2CharCode("ð") + ")");
>
>
>You should implement error checking...
>
>Fox
>***************
works great! (mozilla, IE; on XP) thanks!
|