Roy Smith shared the following utility method
in the Saloon :
private String urlEncoder (String s) {
try {
if (s == null) {
return (s);
}
StringBuffer sb = new StringBuffer(100);
char c;
for (int i = 0; i < s.length(); i++) {
c = s.charAt(i);
if ( (c >= '0' && c <= '9') ||
(c >= 'A' && c <= 'Z') ||
(c >= 'a' && c <= 'z') ) {
sb.append(c);
continue;
}
if (c > 15) {
sb.append("%" + Integer.toHexString( (int) c));
} else {
sb.append("%0" + Integer.toHexString( (int) c));
}
}
return sb.toString();
} catch (Exception e) {
System.out.println("Exception, URLencode string is " + s);
return null;
}
}
JavaMicroEditionFaq