Hi!
> What I need now is a javascript function to unencode this string - is
> there already something in myfaces of do one know a library for this.
>   
Thanks for your tips.
*) \u - you cant convert a &# to \u (even if its the same code what I
don't know now) - however \u will be evaluated at parsing time, so you
cant do something like alert(string.replace("&#", "\u")) nor "\\u"
*) I have absolutely no clue why the \" stuff works, and here I had no
luck with it.

So here is what I do now.
There are only a handful places in our javascript where we alert
something to the user, I'll replace alert( by something like myAlert().
In there, before passing the string to alert() I will convert the string
using the following simple script:

/**
 * decodes all &#nnn; in the given text to its corresponding character
 */
function decodeHexEntity(text)
{
    var entitySearch = /&#[0-9]+;/g;
    var entity;
    while (entity = entitySearch.exec(text))
    {
        var charCode = entity[0].substring(2, entity[0].length -1);
        text = text.substring(0, entity.index)
            + String.fromCharCode(charCode)
            + text.substring(entity.index + entity[0].length);
    }
   
    return text;
}


Maybe not the most performant solution, but easily done and it wont be
used in time critical javascript code ;-)

So maybe someone else might find it useful too.

Ciao,
Mario

Reply via email to