wood burning stoves 2.0
The moose likes Beginning Java and the fly likes replace char Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "replace char" Watch "replace char" New topic

replace char

peter brews
Ranch Hand

Joined: Jan 25, 2002
Posts: 59
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.
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

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.

Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
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:
peter brews
Ranch Hand

Joined: Jan 25, 2002
Posts: 59
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.
I agree. Here's the link: http://aspose.com/file-tools
subject: replace char
It's not a secret anymore!