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 String replacement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String replacement" Watch "String replacement" New topic

String replacement

Mag Yeoh
Ranch Hand

Joined: Oct 08, 2006
Posts: 42

Hi need help.

need to replace the $custId and $BirthDate after retrieve the value from db. use replaceAll only can replace one time.

When return the str, it have nothing change in the str. The value i wan it replace the $custId with Customer Id and $BirthDate with Birthday Date.

Can anyone give idea. Thanks.
D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
replaceAll() returns the changed string, so I think you just need to assign that to your str variable again (str = str.replaceAll(...)).
Rob Spoor

Joined: Oct 27, 2005
Posts: 20274

You may also want to check out java.lang.String#replace(java.lang.CharSequence, java.lang.CharSequence). This method has been added in Java 5.0 and is equal to replaceAll but with literal matching, not regular expression matching.

How To Ask Questions How To Answer Questions
Mag Yeoh
Ranch Hand

Joined: Oct 08, 2006
Posts: 42
Thanks Rob Prime and D. Ogranos.....I get use to it already...

thanks very much
I agree. Here's the link:
subject: String replacement
It's not a secret anymore!