Java Utililty Methods String Encode

List of utility methods to do String Encode

Description

The list of methods to do String Encode are organized into topic(s).

Method

StringencodeUTF8(String s)
string encoding is centralized at this method
if (s != null) {
    s = URLEncoder.encode(s, "UTF-8"); 
return s;
StringencodeUTF8(String s)
encode UTF
try {
    if (s == null || s.equals(""))
        return "";
    s = URLEncoder.encode(s, "UTF-8");
    s = s.replaceAll("\\+", "%20");
    return s;
} catch (Exception e) {
    e.printStackTrace();
...
StringencodeValue(String dirtyValue)
Helper function for character encoding
String cleanValue = "";
try {
    cleanValue = URLEncoder.encode(dirtyValue, "UTF-8").replace("+", "%20");
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
return cleanValue;
StringencodeValue(String str)
Encode a string value to URL encoding standards
try {
    return URLEncoder.encode(str, "UTF-8");
} catch (Exception e) {
    return str;
StringencodeValue(String value)
encode Value
try {
    return URLEncoder.encode(value, "UTF-8").replaceAll("\\+", "%20").replaceAll("\\%21", "!") 
            .replaceAll("\\%27", "'") 
            .replaceAll("\\%28", "(").replaceAll("\\%29", ")").replaceAll("\\%7E", "~"); 
} catch (UnsupportedEncodingException e) {
    return value.replaceAll(" ", "%20").replaceAll("\\%21", "!").replaceAll("\\%27", "'") 
            .replaceAll("\\%28", "(") 
            .replaceAll("\\%29", ")").replaceAll("\\%7E", "~"); 
...