Java URI Encode encodeURIComponent(String component)

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

Description

encode URI Component

License

Open Source License

Declaration

private static String encodeURIComponent(String component) 

Method Source Code


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

import java.net.URLEncoder;

public class Main {
    private static String encodeURIComponent(String component) {
        String result;/*  w  ww  .  ja va2 s .c o  m*/
        try {
            result = URLEncoder.encode(component, "UTF-8").replaceAll("%28", "(").replaceAll("%29", ")")
                    .replaceAll("\\+", "%20").replaceAll("%27", "'").replaceAll("%21", "!").replaceAll("%7E", "~");
        } catch (java.io.UnsupportedEncodingException e) {
            result = component;
        }
        return result;
    }
}

Related

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