Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String replacement

 
Mag Yeoh
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





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
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
replaceAll() returns the changed string, so I think you just need to assign that to your str variable again (str = str.replaceAll(...)).
 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mag Yeoh
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob Prime and D. Ogranos.....I get use to it already...

thanks very much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic