Java URI Encode encodeURIComponent(String input)

Here you can find the source of encodeURIComponent(String input)

Description

encode URI Component

License

Apache License

Declaration

public static String encodeURIComponent(String input) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main {
    public static String encodeURIComponent(String input) {
        try {//  w w w. j a  va2 s  .  c  om
            return URLEncoder.encode(input, "UTF-8").replaceAll(" ", "%20").replaceAll("!", "%21")
                    .replaceAll("'", "%27").replaceAll("\\(", "%28").replaceAll("\\)", "%29")
                    .replaceAll("\\+", "%2B").replaceAll("\\:", "%3A").replaceAll("~", "%7E");
        } catch (UnsupportedEncodingException e) {
        }
        return null;
    }
}

Related

  1. encodeUri(String uri)
  2. encodeUri(URI uri)
  3. encodeURI(URI uri)
  4. encodeURIComponent(final String s)
  5. encodeURIComponent(String component)
  6. encodeURIComponent(String s, String charset)
  7. encodeURIComponent(String uriComp)
  8. encodeUriComponent(String value)
  9. encodeURIComponentForJavaScript(String str)