This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URL Encode in J2ME???

 
Stephen Hanley
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to encode a url in J2ME using the standard packages?

Would it be difficult to write my own class to do this?
 
Stephen Hanley
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be more specific:

I have a String which I wish to include as part of a URL I am calling.

This string is being passed as one of the parameters of a GET call.

The String contains spaces, the String needs to be encoded so that the spaces do not cause a problem.
 
Armando Miranda
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Look at this method I built to encode the tags <> and anothe ones :
When you call this method you pass the String you want to encode and it returns the String encoding. If you need miore funct you could use a while to parse anothers characters.

static public String urlEncode(String sUrl) {
int i = 0;
String urlOK = "";
while (i < sUrl.length()) {
if (sUrl.charAt(i) == '<') {
urlOK = urlOK + "%3C";
} else if (sUrl.charAt(i) == '/') {
urlOK = urlOK + "%2F";
} else if (sUrl.charAt(i) == '>') {
urlOK = urlOK + "%3E";
} else if (sUrl.charAt(i) == ' ') {
urlOK = urlOK + "%20";
} else if (sUrl.charAt(i) == ':') {
urlOK = urlOK + "%3A";
} else if (sUrl.charAt(i) == '-') {
urlOK = urlOK + "%2D";
} else {
urlOK = urlOK + sUrl.charAt(i);
}
i++;
}
return (urlOK);
}

I hope it works to you.

Regards.
Armando M.
 
Nikolay Klimchuk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Minor optimization

[ May 20, 2005: Message edited by: Nikolay Klimchuk ]
 
Michelle de Beer
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found this... Hope it helps you...
http://forum.java.sun.com/thread.jspa?threadID=341790
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic