Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replace a character with characters

 
Owen Jennings
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic