Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Convert from Entity Reference to Hex or Decimal?

Reply
Thread Tools

Convert from Entity Reference to Hex or Decimal?

 
 
kurt
Guest
Posts: n/a
 
      09-18-2004
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
 
Reply With Quote
 
 
 
 
Fox
Guest
Posts: n/a
 
      09-18-2004


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
***************

 
Reply With Quote
 
 
 
 
kurt
Guest
Posts: n/a
 
      09-19-2004
On Sat, 18 Sep 2004 04:00:42 -0500, Fox <> wrote:
>
>
>kurt wrote:
>> hello,
>> Is there a way to convert entity references ( "&atilde;",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("&atilde; = &#" + entity2CharCode("&atilde;"));
>alert("&eth; = %" + entity2Hex("&eth;") +
> " (" + entity2CharCode("&eth;") + ")");
>
>
>You should implement error checking...
>
>Fox
>***************



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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to relate a SQL based entity with an Object based entity in Entity Framework markla ASP .Net 1 10-06-2008 09:42 AM
Entity Name or Entity Number? Samuel van Laere HTML 4 02-24-2007 10:11 PM
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
How to convert an hex string to a Hex number chirs Javascript 3 12-01-2003 10:06 PM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments