File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Replace a character with characters

Owen Jennings

Joined: Jul 15, 2001
Posts: 1
Hey 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!!
David O'Meara

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.
I agree. Here's the link:
subject: Replace a character with characters
It's not a secret anymore!