hello, I am building a search engine in vb.net which would have to search for a word entered by the user in 40 text files within the project directory. It should return the results as the total number of matches (text files) and the number of times this word is in each file. Any suggestions for a start would be grateful.
Regards.
vb.net search engine
Page 1 of 15 Replies - 762 Views - Last Post: 02 November 2011 - 01:44 PM
Replies To: vb.net search engine
#2
Re: vb.net search engine
Posted 02 November 2011 - 12:54 PM
Well there are a million ways of doing this. Probably the simplest in my opinion would be to get all of the text out of the file and into a string using a StreamReader. Then you can use a very simple Regular Expression with just the word you are trying to look for. Then create a MatchCollection with the input and the Regex pattern and see how many matches there are. Repeat this for all the files and hey presto you have you answer.
You could also loop through each word in the file and test it against the word, if it matches increment a counter variable. As I say there are many ways to accomplish this.
You could also loop through each word in the file and test it against the word, if it matches increment a counter variable. As I say there are many ways to accomplish this.
#3
Re: vb.net search engine
Posted 02 November 2011 - 01:27 PM
Thanks for your reply Ryano121, is there any online source I could see ?
Regards.
Regards.
#4
Re: vb.net search engine
Posted 02 November 2011 - 01:40 PM
#5
Re: vb.net search engine
Posted 02 November 2011 - 01:41 PM
Well you can create a new Regex object with the pattern of simply the word you want to find. Then call the .Matches method of the new Regex object. This returns a MatchCollection which essentilly contains all the positions of the matches. All you want to do is get the number of elements in the matchcollection which will be the number of instances of that word. Repeat the same process for all of the text files, each time adding the number of matches to a running total.
#6
Re: vb.net search engine
Posted 02 November 2011 - 01:44 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|