File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adapting My Word Counter Program to also Search and Replace

 
Carl Ryan
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I recently completed a word counter program for a school assignment. It reads in a file name from the command line and prints the contents to the screen before counting the number of words. i now want to try and adapt this program to also search for and replace a word specified by the user and print the document back to the creen with the changes. it would work something like this:
java SearchReplaceApp test.txt
This is a test
This is a test
This is a Test
This is a Test
This file contains 16 words
Search for?: test
Replace with?: Test
This is a Test
This is a Test
This is a Test
This is a Test
Search for?:
etc..........
I was planning on using the
replaceAll
method and obviously i would neeed some kind of loop structure (probably a do/while loop) but i dont really know how to implement this in this scenario.
Any suggestions would be appreciated. NEWBIE ALERT!!! im afraid as i have very little programming experience, so please keep it as simple as possible please.
maybe i'll give you a hug or something
 
Carl Ryan
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to make it easier for you guys to understand heres the code i have for my word counter, which i have now renamed SearchReplaceApp:


as you can see it does use a tokenizer, i would ideally like to be able to replace parts of words as well as whole words and also prompt for another search word after displaying the updated file e.g.
This is a test
Search for?: is
Replace with?: was
Thwas was a test
Search for?:
im really quite stuck on this so suggestions of any kind are welcome
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic