Foros del Web » Programación para mayores de 30 ;) » Java »

ayuda para transformar un string

Estas en el tema de ayuda para transformar un string en el foro de Java en Foros del Web. Amigos; estoy recibiendo en un servlet un mensaje desde una pagina jsp, sin embargo hay caracteres especiales que al ser recepcionado se transforman bajo el ...
  #1 (permalink)  
Antiguo 05/10/2007, 09:45
 
Fecha de Ingreso: noviembre-2005
Mensajes: 70
Antigüedad: 18 años, 5 meses
Puntos: 1
ayuda para transformar un string

Amigos;

estoy recibiendo en un servlet un mensaje desde una pagina jsp,
sin embargo hay caracteres especiales que al ser recepcionado se transforman bajo el sigiente formato %xx, alguien sabe de alguna funcion que me pueda desincriptar este String

a continuacion envio el mensaje original y luego el mensaje que es recepcionado por el servlet

de antemano muchas gracias por su ayuda;

mensaje Original;
Cita:
<MPOUT><a></a><CODRET>0000</CODRET><DESCRET>Transaccion%0OK</DESCRET><IDCOM>9668312079</IDCOM><IDTRX>C001030300044389</IDTRX><TOTAL>150000</TOTAL><NROPAGOS>1</NROPAGOS><FECHATRX>20060908114657</FECHATRX><FECHACONT>20060909</FECHACONT><NUMCOMP>0011223344</NUMCOMP><IDREG>10567</IDREG></MPOUT>
mensaje recepcionado por el servlet

Cita:
%3CMPOUT%3E%3Ca%3E=%3C%2Fa%3E%3CCODRET%3E0000%3C%2 FCODRET%3E%3CDESCRET%3ETransaccion%2520OK%3C%2FDES CRET%3E%3CIDCOM%3E9668312079%3C%2FIDCOM%3E%3CIDTRX %3EC001030300044389%3C%2FIDTRX%3E%3CTOTAL%3E150000 %3C%2FTOTAL%3E%3CNROPAGOS%3E1%3C%2FNROPAGOS%3E%3CF ECHATRX%3E20060908114657%3C%2FFECHATRX%3E%3CFECHAC ONT%3E20060909%3C%2FFECHACONT%3E%3CNUMCOMP%3E00112 23344%3C%2FNUMCOMP%3E%3CIDREG%3E10567%3C%2FIDREG%3 E%3C%2FMPOUT%3E
  #2 (permalink)  
Antiguo 05/10/2007, 11:55
 
Fecha de Ingreso: noviembre-2005
Mensajes: 70
Antigüedad: 18 años, 5 meses
Puntos: 1
Re: ayuda para transformar un string

jeje me estoy respondiendo solo

aqui hay una clase que hace lo que andaba buscando
http://www.w3.org/International/unescape.java

igual dejare el codigo
Cita:
private static String unescape(String s) {
StringBuffer sbuf = new StringBuffer () ;
int l = s.length() ;
int ch = -1 ;
int b, sumb = 0;
for (int i = 0, more = -1 ; i < l ; i++) {
/* Get next byte b from URL segment s */
switch (ch = s.charAt(i)) {
case '%':
ch = s.charAt (++i) ;
int hb = (Character.isDigit ((char) ch)
? ch - '0'
: 10+Character.toLowerCase((char) ch) - 'a') & 0xF ;
ch = s.charAt (++i) ;
int lb = (Character.isDigit ((char) ch)
? ch - '0'
: 10+Character.toLowerCase ((char) ch)-'a') & 0xF ;
b = (hb << 4) | lb ;
break ;
case '+':
b = ' ' ;
break ;
default:
b = ch ;
}
/* Decode byte b as UTF-8, sumb collects incomplete chars */
if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte)
sumb = (sumb << 6) | (b & 0x3f) ; // Add 6 bits to sumb
if (--more == 0) sbuf.append((char) sumb) ; // Add char to sbuf
} else if ((b & 0x80) == 0x00) { // 0xxxxxxx (yields 7 bits)
sbuf.append((char) b) ; // Store in sbuf
} else if ((b & 0xe0) == 0xc0) { // 110xxxxx (yields 5 bits)
sumb = b & 0x1f;
more = 1; // Expect 1 more byte
} else if ((b & 0xf0) == 0xe0) { // 1110xxxx (yields 4 bits)
sumb = b & 0x0f;
more = 2; // Expect 2 more bytes
} else if ((b & 0xf8) == 0xf0) { // 11110xxx (yields 3 bits)
sumb = b & 0x07;
more = 3; // Expect 3 more bytes
} else if ((b & 0xfc) == 0xf8) { // 111110xx (yields 2 bits)
sumb = b & 0x03;
more = 4; // Expect 4 more bytes
} else /*if ((b & 0xfe) == 0xfc)*/ { // 1111110x (yields 1 bit)
sumb = b & 0x01;
more = 5; // Expect 5 more bytes
}
/* We don't test if the UTF-8 encoding is well-formed */
}
return sbuf.toString() ;
}
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:35.