Java String Encode encodeThoroughly(String s)

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

Description

encode Thoroughly

License

Open Source License

Declaration

public static String encodeThoroughly(String s) 

Method Source Code


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

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

public class Main {
    private static final String defaultFormat = "utf-8";

    public static String encodeThoroughly(String s) {
        String result;/*from  w  w w  .j  a  v  a2s.c o  m*/

        try {
            result = URLEncoder.encode(s, "UTF-8").replaceAll("\\+", "%20").replaceAll("\\%21", "!")
                    .replaceAll("\\%27", "'").replaceAll("\\%28", "(").replaceAll("\\%29", ")")
                    .replaceAll("\\%7E", "~");
        } catch (UnsupportedEncodingException e) {
            result = s;
        }

        return result;
    }

    public static String encode(String input) {
        String encodedInput = "";
        try {
            encodedInput = URLEncoder.encode(input, defaultFormat);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        assert (encodedInput.length() > 0);
        return encodedInput;
    }
}

Related

  1. encodeStringByUTF8(String str)
  2. encodeText(String str)
  3. encodeText(String str, String fromEnc, String toEnc)
  4. encodeTexts(String s)
  5. encodeTextValue(char[] characters, int offset, int length, Writer writer)
  6. encodeToFlex(Object o)
  7. encodeToForm(Map msg)
  8. encodeToString(String s)
  9. encodeURNComponent(String value)