jukkauusi
asked on
URLEncoded to String
How can I convert Urlencoded string back 'normal' string?
something like:
String s = URLEncoder.encode("T S");
String s1 = IneedThis.toString();
and s1 should be "T S".
something like:
String s = URLEncoder.encode("T S");
String s1 = IneedThis.toString();
and s1 should be "T S".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Download :
ftp://ftp.oreilly.com/published/oreilly/java/java.netprog/javanetexamples.zip
Once deziped :
javanetexamples\05\URLDeco der.java
......
courtesy of 'pyxide'
ftp://ftp.oreilly.com/published/oreilly/java/java.netprog/javanetexamples.zip
Once deziped :
javanetexamples\05\URLDeco
......
courtesy of 'pyxide'
ASKER
Thanks,
I made same kind of method as this URLDecoder.decode. My version is
private String MakeCleanString(String s) {
String rc="";
for(int i=0;i<s.length();i++) {
if(s.charAt(i)=='+') {
rc+=' ';
continue;
}
if(s.charAt(i)=='%') {
rc+=(char) Integer.decode("0x"+s.subs tring(i+1, i+3)).intV alue();
i+=2;
continue;
}
rc+=s.charAt(i);
}
return rc;
}
Do You find any problems with that one?
But You got points, anyway.
I made same kind of method as this URLDecoder.decode. My version is
private String MakeCleanString(String s) {
String rc="";
for(int i=0;i<s.length();i++) {
if(s.charAt(i)=='+') {
rc+=' ';
continue;
}
if(s.charAt(i)=='%') {
rc+=(char) Integer.decode("0x"+s.subs
i+=2;
continue;
}
rc+=s.charAt(i);
}
return rc;
}
Do You find any problems with that one?
But You got points, anyway.
hey it's very nice!
see from https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=10223004
use this and name this class as URLDecoder
public class URLDecoder
{
public static String decode(String s) {
ByteArrayOutputStream out = new ByteArrayOutputStream(s.le
for (int i = 0; i < s.length(); i++) {
int c = (int) s.charAt(i);
if (c == '+') {
out.write(' ');
}
else if (c == '%') {
int c1 = Character.digit(s.charAt(+
int c2 = Character.digit(s.charAt(+
out.write((char) (c1 * 16 + c2));
}
else {
out.write(c);
}
} // end for
return out.toString();
}
}