Convert from Entity Reference to Hex or Decimal?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kurt

    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
  • Fox

    #2
    Re: Convert from Entity Reference to Hex or Decimal?



    kurt wrote:[color=blue]
    > 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[/color]

    These might work:

    var gDiv = null;

    function
    entity2CharCode (ent)
    {
    var retval = null;

    if(!gDiv)
    gDiv = document.create Element('DIV');

    gDiv.innerHTML = ent;

    return gDiv.innerHTML. charCodeAt(0);
    }

    function
    entity2Hex(ent)
    {

    if(!gDiv)
    gDiv = document.create Element('DIV');

    gDiv.innerHTML = ent;

    return gDiv.innerHTML. charCodeAt(0).t oString(16).toU pperCase();
    }

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


    You should implement error checking...

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

    Comment

    • kurt

      #3
      Re: Convert from Entity Reference to Hex or Decimal?

      On Sat, 18 Sep 2004 04:00:42 -0500, Fox <fox@fxmahoney. com> wrote:[color=blue]
      >
      >
      >kurt wrote:[color=green]
      >> 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[/color]
      >
      >These might work:
      >
      >var gDiv = null;
      >
      >function
      >entity2CharCod e(ent)
      >{
      >var retval = null;
      >
      > if(!gDiv)
      > gDiv = document.create Element('DIV');
      >
      > gDiv.innerHTML = ent;
      >
      > return gDiv.innerHTML. charCodeAt(0);
      >}
      >
      >function
      >entity2Hex(ent )
      >{
      >
      > if(!gDiv)
      > gDiv = document.create Element('DIV');
      >
      > gDiv.innerHTML = ent;
      >
      > return gDiv.innerHTML. charCodeAt(0).t oString(16).toU pperCase();
      >}
      >
      >alert("&atilde ; = &#" + entity2CharCode ("&atilde;") );
      >alert("&eth; = %" + entity2Hex("&et h;") +
      > " (" + entity2CharCode ("&eth;") + ")");
      >
      >
      >You should implement error checking...
      >
      >Fox
      >************** *[/color]


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

      Comment

      Working...