aspose file tools*
The moose likes Java in General and the fly likes Occurence of given string in a large text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Occurence of given string in a large text file" Watch "Occurence of given string in a large text file" New topic
Author

Occurence of given string in a large text file

Hs Raveendran
Greenhorn

Joined: Feb 05, 2010
Posts: 23

Which is the efficient algorithm to find the occurrence of a given string in a given large text file.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Hs Raveendran wrote:Which is the efficient algorithm to find the occurrence of a given string in a given large text file.


There are two prime algorithms for doing this - the Knuth-Morris-Pratt algorithm and the Boyer-Moore algorithm. Both are fairly easy to implement and Google will provide the details. In this case I would probably use the Knuth-Morris-Pratt algorithm since it requires no backtracking.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Occurence of given string in a large text file