Find Functionality

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 54
Reputation: Pgmer is an unknown quantity at this point 
Solved Threads: 5
Pgmer Pgmer is offline Offline
Junior Poster in Training

Find Functionality

 
0
  #1
Jul 1st, 2008
Hai all,

in my appliction Im writing functionality to find keywords entered by user
if keyword found i need to return the 10 words before keyword and 10 words after keywords, Im able to find the keywords using Instr method.. Im not getting how to get 10 words Before and after keywords.. Any one hae idea? if you have sample code Then it would more help full

Thanks In advance.
Last edited by Pgmer; Jul 1st, 2008 at 7:46 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Find Functionality

 
0
  #2
Jul 1st, 2008
Here is one way.
Three textboxes and button.
  1. Public Class Form1
  2. Dim KeyWord As String = "aid"
  3.  
  4. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5. TextBox1.Text = "Now is the time for all good men to come to the aid of their country the quick brown fox jumps over the lazy dog"
  6. End Sub
  7.  
  8. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  9. Dim Ary() As String = Nothing
  10. Ary = TextBox1.Text.Split(" ")
  11. Dim index As Integer = 0
  12. For index = 0 To UBound(Ary)
  13. If Ary(index) = KeyWord Then
  14. Exit For
  15. End If
  16. Next
  17. If index <= UBound(Ary) Then
  18. For i As Integer = index - 10 To index - 1
  19. TextBox2.Text &= Ary(i) & " "
  20. Next
  21. For i As Integer = index + 1 To index + 10
  22. TextBox3.Text &= Ary(i) & " "
  23. Next
  24. End If
  25. End Sub
  26. End Class
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 2
Reputation: SWdevelopment is an unknown quantity at this point 
Solved Threads: 1
SWdevelopment SWdevelopment is offline Offline
Newbie Poster

Re: Find Functionality

 
0
  #3
Jul 2nd, 2008
Hum, That's good and easy coding stuffs, thanks for sharing man.
www.cygnet-infotech.com
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 54
Reputation: Pgmer is an unknown quantity at this point 
Solved Threads: 5
Pgmer Pgmer is offline Offline
Junior Poster in Training

Re: Find Functionality

 
0
  #4
Jul 2nd, 2008
Thank u. thats good idea.
But i need to find the paragraph.
in entire document there may be 100's of paragraph but i need to get only those paragraph in which the key word is found.....
pls help me out.....

thanks again..
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 48
Reputation: Ken Sharpe is an unknown quantity at this point 
Solved Threads: 2
Ken Sharpe's Avatar
Ken Sharpe Ken Sharpe is offline Offline
Light Poster

Re: Find Functionality

 
0
  #5
Jul 2nd, 2008
Not clear -- you want to find 10 words before, and 10 after any keyword, but only if the words are inside a paragraph?

Like, the keyword is the firs word in a given paragraph, so you'd only want 10 words after?

You just need to search for the line break before, and the line break after, then only search inside that block. Then, search for 10 space characters before and after, and include every character between those two indexes.
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Find Functionality

 
0
  #6
Jul 2nd, 2008
Try this then:
  1. Public Class Form1
  2. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3. TextBox1.Text = "The quick brown fox jumps over the lazy dog" & vbNewLine
  4. TextBox1.Text &= "Now is the time for all good men to come to the aid of their country" & vbNewLine
  5. TextBox1.Text &= "This is a test for finding all."
  6. End Sub
  7.  
  8. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  9. Dim ary As String()
  10. ary = TextBox1.Text.Split(vbNewLine)
  11. For index As Integer = 0 To UBound(ary)
  12. If ary(index).IndexOf("the") <> -1 Then
  13. MessageBox.Show(ary(index))
  14. End If
  15. Next
  16. End Sub
  17. End Class
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 54
Reputation: Pgmer is an unknown quantity at this point 
Solved Threads: 5
Pgmer Pgmer is offline Offline
Junior Poster in Training

Re: Find Functionality

 
0
  #7
Jul 3rd, 2008
Thank u both ken sharpe and waynespangler for ur response.

what exactly i want is .

Say in document there may be 100 paragrphs out of which only 10 paragraph contains the keyword for which im searching for. i have to return those 10 paragraphs which have the keyword. if keyword is at start of paragraph then it should pick that paragraph and keep serching for the next paragraphs in which key word is there untill it reaches the end of document.
Hope this is clear...
Pls share ur ideas.
Thanks
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: Find Functionality

 
0
  #8
Jul 3rd, 2008
If you tried the last code I sent, you will see it does what you want.
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 54
Reputation: Pgmer is an unknown quantity at this point 
Solved Threads: 5
Pgmer Pgmer is offline Offline
Junior Poster in Training

Re: Find Functionality

 
0
  #9
Jul 3rd, 2008
It works. Thank u very much.
Last edited by Pgmer; Jul 3rd, 2008 at 8:24 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC