There is any way to convert this string: "Coordenação" to this: "Coordenação" in javascript/jquery?

86 views Asked by At

I need to make a search but my dada are encoded (in JSON OBJECT) like this: Coordenação and when i type "Coordenação" on input I didn't find nothing.

I want to know if have any function to convert Coordenação to Coordenação

I'm not sure but I think "Coordenação" is UTF-8 encoding and other string is ISO-8859-1

I get the correct string from my oracle database, and it shows correctly in browser, but when i see my code source with my browser, i see my json object with these characters (I'm making a json object with data from database).

I'm searching for hours how to fix this with other solution but without success, now I'm trying to do convert the data typed on input to match with json data.

1

There are 1 answers

1
Joao Paulo On BEST ANSWER

Thank You @Jonathan. I found the solution in your link.

This function do exact what I want:

    function encodeHTML(str) {
        var aStr = str.split(''),
            i = aStr.length,
            aRet = [];

        while (--i) {
            var iC = aStr[i].charCodeAt();
            if (iC < 65 || iC > 127 || (iC > 90 && iC < 97)) {
                aRet.push('&#' + iC + ';');
            } else {
                aRet.push(aStr[i]);
            }
        }
        return aRet.reverse().join('');
    }