5 Replies - 2107 Views - Last Post: 02 November 2011 - 01:44 PM Rate Topic: -----

#1 Don_H  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-November 11

vb.net search engine

Posted 02 November 2011 - 12:50 PM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: vb.net search engine

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

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.
Was This Post Helpful? 0
  • +
  • -

#3 Don_H  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-November 11

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.
Was This Post Helpful? 0
  • +
  • -

#4 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: vb.net search engine

Posted 02 November 2011 - 01:40 PM

What have you tried?

Msdn docs:
http://msdn.microsof...reamreader.aspx
Was This Post Helpful? 0
  • +
  • -

#5 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

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.
Was This Post Helpful? 0
  • +
  • -

#6 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: vb.net search engine

Posted 02 November 2011 - 01:44 PM

Info on Regex:
http://msdn.microsof...ions.regex.aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1