aspose file tools*
The moose likes Java in General and the fly likes Adapting My Word Counter Program to also Search and Replace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Adapting My Word Counter Program to also Search and Replace " Watch "Adapting My Word Counter Program to also Search and Replace " New topic
Author

Adapting My Word Counter Program to also Search and Replace

Carl Ryan
Greenhorn

Joined: Mar 04, 2004
Posts: 2
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

Joined: Mar 04, 2004
Posts: 2
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
 
subject: Adapting My Word Counter Program to also Search and Replace