Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inserting into strings

 
kevin schmidt
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a string that contains spaces in it. Now I want to 'replace' those spaces with %20. How do I go about doing that? Also, the number of spaces in the string can vary. TIA.
Kevin
 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kevin
Have a look at:
http://www.javaranch.com/ubb/Forum33/HTML/004104.html
Hope this helps
Michael

------------------
"One good thing about music - when it hits, you feel no pain"
Bob Marley
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not entirely what you asked for, but if you're trying to do what I think you're trying to do have a look at java.net.URLEncoder.
- Peter
 
kevin schmidt
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I managed to figure it out yesterday, and what the Java.net.URLEncoder does is... well... I'm not too sure, but the encoding scheme of it is not the same as if you look up "URL Encoding" on google or something. What I was looking for was to replace spaces with "%20", but when using the java encoder class, it gave me a "+" and also encoded a lot more than I wanted to. I just wrote my own routine and it does exactly what I wanted it to. Thanks though.
kevin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic