Here you can find the source of decodeURIComponent(String s, String charset)
decodeURIComponent
function.
Parameter | Description |
---|---|
s | The encoded String to be decoded |
charset | a parameter |
public static String decodeURIComponent(String s, String charset)
//package com.java2s; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; public class Main { /**//from www . java 2s . co m * Decodes the passed UTF-8 String using an algorithm that's compatible with * JavaScript's <code>decodeURIComponent</code> function. Returns * <code>null</code> if the String is <code>null</code>. * * @param s The UTF-8 encoded String to be decoded * @return the decoded String */ public static String decodeURIComponent(String s) { return decodeURIComponent(s, "UTF-8"); } /** * Decodes the passed String using an algorithm that's compatible with * JavaScript's <code>decodeURIComponent</code> function. Returns * <code>null</code> if the String is <code>null</code>. * * @param s The encoded String to be decoded * @param charset * @return the decoded String */ public static String decodeURIComponent(String s, String charset) { if (s == null) { return null; } String result = null; try { result = URLDecoder.decode(s, charset); } // This exception should never occur. catch (UnsupportedEncodingException e) { result = s; } return result; } }