Java URL Decode urlDecode(String scope)

Here you can find the source of urlDecode(String scope)

Description

Performs url decoding.

License

Open Source License

Declaration

public static String urlDecode(String scope) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /** Performs url decoding.
     */*www .  j a v a2 s.c  o  m*/
     * This utility function percent encodes a text so that it can be
     * embodied verbatim in a URL (e.g. as a fragment).
     *
     * @see #urlEncode(String scope)
     */
    public static String urlDecode(String scope) {
        StringBuffer result = new StringBuffer();

        for (int i = 0; i < scope.length(); ++i) {
            char c = scope.charAt(i);

            if (c == '+') {
                result.append(' ');
            } else if (c == '%' && i + 2 < scope.length()) {
                int start = i + 1;
                String h = scope.substring(start, start + 2);
                try {
                    long hval = Long.parseLong(h, 16);
                    result.append("" + (byte) hval);
                } catch (NumberFormatException nfe) {
                    result.append(c);
                }
            } else {
                result.append(c);
            }
        }

        return result.toString();
    }
}

Related

  1. safeDecode(String s)
  2. unescape(String s)
  3. unescape(String string)
  4. unescape(String theString)
  5. urlDecode(String s)
  6. URLDecode(String str)
  7. urldecode(String str)
  8. urlDecode(String str)
  9. urlDecode(String text)