Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaScript/java equivalent function?

 
Ravi Mandalapu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there any equivalent javascript's escape() function in java?
I want to hex-encode in java, that's why i need that function.
Any help would be greatly appeciate.
Thankx,
Ravi
 
Cynthia Yao
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please check the api looking for java.net.URLEncoder. The class contains a utility method for converting a String into a MIME format called "x-www-form-urlencoded" format.
 
Ravi Mandalapu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Cynthia Yao,
Thank you very much for your response.
yes, u are right, but the problem is it is replacing spaces with "+". In result i am displaying + symbols....
If you have any suggessions, please let me know...
Thank you.
Ravi
 
spalaniv
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Cynthia is right.
public class URLEncoder
extends Object
The class contains a utility method for converting a String into a MIME format called "x-www-form-urlencoded" format.
To convert a String, each character is examined in turn:
The ASCII characters 'a' through 'z', 'A' through 'Z', and '0' through '9' remain the same.
The space character ' ' is converted into a plus sign '+'.
All other characters are converted into the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the lower 8-bits of the character.
 
Ravi Mandalapu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI spalaniv,
Thank you very much for your response.
My problem is I am devoloping Mailing system.(Using mailto://)
In body we will get result with + marks..
I don't want to see like that.
Just i want to see like spaces instead of + marks..
Is there any other solution for that?
I will be greatly appreciate for your response.
ravi

Yes, Cynthia is right.
public class URLEncoder
extends Object
The class contains a utility method for converting a String into a MIME format called "x-www-form-urlencoded" format.
To convert a String, each character is examined in turn:
The ASCII characters 'a' through 'z', 'A' through 'Z', and '0' through '9' remain the same.
The space character ' ' is converted into a plus sign '+'.
All other characters are converted into the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the lower 8-bits of the character.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic