Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Wiki
Search Coderanch
Advance search
Google search
Register / Login
Bookmark Topic
Watch Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Wiki
Url Encoding For Mobile Java
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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) { // if it's a non-control char, ie. >x0F, just add % and the string sb.append("%" + Integer.toHexString( (int) c)); } else { // otherwise we need to add a leading 0 sb.append("%0" + Integer.toHexString( (int) c)); } } return sb.toString(); } catch (Exception e) { System.out.println("Exception, URLencode string is " + s); return null; } }
JavaMicroEditionFaq
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
protected field access error
characters and numbers seperation in a string
best way to check whether a character is uppercase?
Looping StringBuffer
Chinese Attached filename can't be shown
More...