Android URL Encode encode(String value)

Here you can find the source of encode(String value)

Description

encode

Declaration

public static String encode(String value) 

Method Source Code

//package com.java2s;

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;

public class Main {
    public static String encode(String value) {
        String encoded = "";
        try {//from   ww  w.  j ava2s .c om
            encoded = URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException ignore) {
        }
        StringBuffer buf = new StringBuffer(encoded.length());
        char focus;
        for (int i = 0; i < encoded.length(); i++) {
            focus = encoded.charAt(i);
            if (focus == '*') {
                buf.append("%2A");
            } else if (focus == '+') {
                buf.append("%20");
            } else if (focus == '%' && (i + 1) < encoded.length()
                    && encoded.charAt(i + 1) == '7'
                    && encoded.charAt(i + 2) == 'E') {
                buf.append('~');
                i += 2;
            } else {
                buf.append(focus);
            }
        }
        return buf.toString();

    }
}

Related

  1. encodeURI(String encoded)
  2. encode(String base)
  3. encode(String url)
  4. urlEncode(String url)