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".

 
jukkauusiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbormannCommented:
>>>>>String s1 = IneedThis.toString();

String s1 = URLDecoder.decode(s);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbormannCommented:
oops ,i forgot to add this ,soory for that .
see from http://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.length());
             
                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(++i), 16);
                    int c2 = Character.digit(s.charAt(++i), 16);
                    out.write((char) (c1 * 16 + c2));
                  }
                  else {
                    out.write(c);
                  }
                } // end for

                return out.toString();
               
              }
}
0
mbormannCommented:
Download :
            ftp://ftp.oreilly.com/published/oreilly/java/java.netprog/javanetexamples.zip 

Once deziped :
javanetexamples\05\URLDecoder.java

......
courtesy of 'pyxide'
0
jukkauusiAuthor Commented:
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.substring(i+1,i+3)).intValue();
        i+=2;
        continue;
        }
      rc+=s.charAt(i);
      }
    return rc;
    }

Do You find any problems with that one?

But You got points, anyway.
0
mbormannCommented:
hey it's very nice!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.