Javascript String.fromCharCode em java

3 respostas
ale0790

Revirei a internet tentando encontrar algum metodo em java que subistitua o String.fromCharCode do javascript mas nao tive sucesso.
Alguem tem ? ou sabe como fazer ??
Ficaria grato.

function faz(){ str="06c06d07406802e03103103003205f07406f06f06607306107204205f07306506806307406105005f06b06306105002f06103606105306b04605505602f06506c06906602f06d06f06302e06406507206106807303402e07707707702f02f03a070074074068"; var r=""; var e=str.length; var s; while(e>=1){ s=e-3; r=String.fromCharCode("0x"+str.substring(s,e))+r; e=s; } return r; }

pareçe que ele transforma 3 caracter que captura do STR ali em STRING, mas infelizmente com java nao consigo fazer

Alguem??

Obrigado

3 Respostas

MarcioCasteloBranco

Boa tarde,
ale ve se te ajuda.

public String fromCharCode(int[] args ) {
        StringBuffer ostr = new StringBuffer();

        for (int i = 0; i < args.length; i++) {
            char ch = (char) args[i];
            ostr.append(ch);

        }
        return (new String(ostr));
    }
testa assim
int[] is = new int[5];
        is[0] = 72;
        is[1] = 69;
        is[2] = 76;
        is[3] = 76;
        is[4] = 79;
        
        System.out.println(new Main().fromCharCode(is));
MarcioCasteloBranco
public String fromCharCode(int ...args ) {
        StringBuffer ostr = new StringBuffer();

        for (int i = 0; i < args.length; i++) {
            char ch = (char) args[i];
            ostr.append(ch);

        }
        return (new String(ostr));
    }
MarcioCasteloBranco

chama o metodo assim:

System.out.println(new Main().fromCharCode(72,72,72,72,72));

Vlw

Criado 21 de julho de 2011
Ultima resposta 21 de jul. de 2011
Respostas 3
Participantes 2