Here you can find the source of weakUrlEncode(String url)
public static String weakUrlEncode(String url)
//package com.java2s; public class Main { /** /*from w w w . j a v a 2 s. c om*/ * Doesn't encode characters such as: ":", ";", etc. * Behaves like Cocoa's stringByEscaping function. We mostly use this to ensure * server compatibility but ideally the server would grow up. :) */ public static String weakUrlEncode(String url) { if (url == null) return null; // make sure you don't have a duplicate character in both lists or it will break. String[] reserved = { ";", "?", " ", "&", "=", "$", ",", "[", "]", "#", "!", "'", "(", ")", "*" }; String[] escaped = { "%3B", "%3F", "+", "%26", "%3D", "%24", "%2C", "%5B", "%5D", "%21", "%27", "%28", "%28", "%29", "%2A" }; StringBuilder encUrl = new StringBuilder(url); //cycle through and keep replacing (bit inefficient, but sue me!) for (int i = 0; i < escaped.length; i++) { String res = reserved[i]; String esc = escaped[i]; // replace all occurrences int index = encUrl.indexOf(res); while (index != -1) { encUrl.replace(index, index + res.length(), esc); index = encUrl.indexOf(res); } } return encUrl.toString(); } }