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 Count the String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Count the String" Watch "Count the String" New topic
Author

Count the String

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1376
I want to find out how many times String 'java' appeared in the particular file. How can i do that?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
What have you tried? So far we don' know if you're stuck reading a file, finding the string "java", counting or showing the results.

Some places to look in the JavaDoc: File & FileReader, String.indexOf(), Pattern & Matcher. See if any of those get you going. If you get part way and get stuck, show us some code and we'll help keep you moving.

Take small steps - don't try to write the whole program in one sitting - and have fun!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

  • Open the file
  • Read each line
  • If you find "java" increment a counter


  • Which part are you unsure how to do?


    JavaRanch FAQ HowToAskQuestionsOnJavaRanch
    Stan James
    (instanceof Sidekick)
    Ranch Hand

    Joined: Jan 29, 2003
    Posts: 8791
    But Paul wouldn't want you to forget to test with a line that says

    How about punctuation? Only you know your rules here. Maybe lines like:

     
    GeeCON Prague 2014
     
    subject: Count the String