• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

replace char

 
peter brews
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I need to replace all ocurrences of &
with &.Could you please tell how do i acheive this.
I think I can't use replace(oldchar,newchar) function here.
Thanks,
smita
 
Barry Andrews
Ranch Hand
Posts: 523
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You said that you want to replace & with & or is that & with a dot at the end??? Please clarify what you are trying to do. If you want to replace all instances of one char with another char you can use the replace() method. But if you need to replace with more than 1 char, I think you will have to write your own method for that.

Barry
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The String class has a new method or two since JDK 1.4. You may want to take a look at replaceAll and/or replaceFirst.
Good Luck.
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure that you meant replace all occurances of & with &. but UUB messed it up for you.
I wrote a function to escape HTML in my StringHelper class. There is also a function that will do a general find and replace in there:
http://ostermiller.org/utils/StringHelper.html
 
peter brews
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you all and Steve.You are right Steve I want to replace a char with a string.Also I would like to know for JDK1.4 only the beat version is available or the production version is also avaliable.
Thanks,
smita
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic