public static String escape(String s) { String newstr = ""; for (char c : s.toCharArray()) { if (Character.isLetterOrDigit(c)) newstr += c; else if (c == ' ') newstr += "+"; else { String hex = Integer.toHexString(c); if (hex.length() == 1) hex = "0" + hex; newstr += "%" + hex.toUpperCase(); } }