Java String Escape percentEncode(String s)

Here you can find the source of percentEncode(String s)

Description

percent Encode

License

Apache License

Declaration

public static String percentEncode(String s) 

Method Source Code

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

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

public class Main {
    public static final String ENCODING = "UTF-8";

    public static String percentEncode(String s) {
        if (s == null) {
            return "";
        }/*from w w  w . ja v a 2 s.  c om*/
        try {
            return URLEncoder.encode(s, ENCODING)
                    // OAuth encodes some characters differently:
                    .replace("+", "%20").replace("*", "%2A")
                    .replace("%7E", "~");
        } catch (UnsupportedEncodingException uee) {
            throw new RuntimeException(uee.getMessage(), uee);
        }
    }
}

Related

  1. escapeUnsafeCharacters(String anyURI, boolean escapePercent)
  2. escapeWiki(String s)
  3. escapeXML(String message)
  4. escapeXml(String str)
  5. escapeXML(String str)
  6. percentEncode(String s)
  7. percentEncode(String value)
  8. percentEncode(String value, String encoding)
  9. percentEncodeRfc3986(final String string)