473,223 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,223 software developers and data experts.

Convert from Entity Reference to Hex or Decimal?

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
Jul 23 '05 #1
2 4602
Fox


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

Jul 23 '05 #2
On Sat, 18 Sep 2004 04:00:42 -0500, Fox <fo*@fxmahoney.com> 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!
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ed Dennison | last post by:
I'm starting to look at DocBook-XML (not SGML) for producing a large documentation set. The hierarchy of DocBook elements for organizing the content is (more or less); set book part chapter...
11
by: Douglas Reith | last post by:
Hi There, Can someone please tell me why the XML spec states that an attribute value with an external entity is forbidden? Or point me to the appropriate document? Or better still, perhaps you...
38
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I...
9
by: Jukka K. Korpela | last post by:
I noticed that Internet Explorer (6.0, on Win XP SP 2, all fixes installed) incorrectly renders e.g. &harr &euro &Omega literally and not as characters denoted by the entities, but if a semicolon...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
13
by: Jason | last post by:
Could someone here show me how I would write a vb program to convert decimal ip address to binary? For example a small form with a convert button and a label for the result and a textbox for the...
6
by: Tuomas Rannikko | last post by:
Hello, I'm currently writing a XML processor for the fun of it. There is something I don't understand in the spec though. I'm obviously missing something important. The spec states that both...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
8
by: Steven D'Aprano | last post by:
I have a string containing Latin-1 characters: s = u" and many more..." I want to convert it to HTML entities: result => "&copy; and many more..." Decimal/hex escapes would be...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.