File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

String replacement

Mag Yeoh
Ranch Hand

Joined: Oct 08, 2006
Posts: 40





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
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mag Yeoh
Ranch Hand

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

thanks very much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String replacement
 
Similar Threads
Regex for adding CDATA to XML nodes
String input with parenthesis
Spring MVC question
Problem when doing replace
String replaceAll()