File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes appendReplacement & replaceAll Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "appendReplacement & replaceAll " Watch "appendReplacement & replaceAll " New topic
Author

appendReplacement & replaceAll

pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 338
Hi to all
Anybody let me know about appendReplacement & replaceAll methods.I am unable to understand the difference between them.I have also read from sun documentation but unable to understand.Please any one explain me both with suitable examples.Are they present in the syallabus of scjp 5.


SCJP 5.0(75%), SCWCD 5.0(88%)
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 338
Please tell me above given.
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
I don't know what you exactly mean, but maybe the api of the String replaceAll could help.


String


Maybe for getting better help you could make you're problem more clear.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 14604

The find(), appendReplacement(), and appendTail() methods are supposed to be used together to find a match based on a regular expression, and then replace it with a replacement string. The replacement string is calculated with Java code.

Although, this is incredibly powerful, it is also a little awkward to use (for people that want to use regular expressions replacement strings instead of using Java to calculate the replacement string).

The replaceFirst() and replaceAll() methods allows the user to simply specify a regular expression and the regex replacement string -- as parameters. This makes it much simpler to use, and not as flexible. Also, these two methods are actually convenience methods, as they are build upon the find(), and appendXXX() methods.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
 
subject: appendReplacement & replaceAll
 
Threads others viewed
Help with Regular Expressions
string.replaceall() and java.util.regex.Pattern/Matcher
Help with regex
The appendReplacement and appendTail
Regex for Init Cap
IntelliJ Java IDE