File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Replace a character with characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Replace a character with characters" Watch "Replace a character with characters" New topic
Author

Replace a character with characters

Owen Jennings
Greenhorn

Joined: Jul 15, 2001
Posts: 1
Hey all...so I think I have sorta an idea of how to do this but wanted to get some recommendations/advice!
I pull a string from the DB which will be something like 3-5,15-18,40-42,50-54 You get the idea...what I need it to be for web display is 3-5, 15-18, 40-42, 50-54 . So I need to replace each instance of , with , (space).
I know you can replace 1 character with another but I have been unable to find something on replacing 1 character with multiple characters.
What is the best way to do this? Thanks a million!!
Owen
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

There is a String.replace(char, char) but you can't use this if you want to add a "comma space" which is a String, not a char.
You'll probably want to use a StringTokenizer to cut the String at each comma and a StringBuffer to paste the results together.
Dave.
 
wood burning stoves
 
subject: Replace a character with characters