search text in a doc file

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

Join Date: Jan 2007
Posts: 47
Reputation: kapil.goyal is an unknown quantity at this point 
Solved Threads: 0
kapil.goyal kapil.goyal is offline Offline
Light Poster

search text in a doc file

 
0
  #1
Apr 13th, 2007
how i can check any text string in a doc file.the searchinh should be fast as i have to do other code if it found the string
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: search text in a doc file

 
0
  #2
Apr 14th, 2007
Are you talking about a file on disk or loaded into a richtext or text box? The latter two can be done with the InStr function.
Unles you want to load the file into memory the first is a lot harder and slower to do.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 47
Reputation: kapil.goyal is an unknown quantity at this point 
Solved Threads: 0
kapil.goyal kapil.goyal is offline Offline
Light Poster

Re: search text in a doc file

 
0
  #3
Apr 16th, 2007
Originally Posted by waynespangler View Post
Are you talking about a file on disk or loaded into a richtext or text box? The latter two can be done with the InStr function.
Unles you want to load the file into memory the first is a lot harder and slower to do.


i m talking abt file on disk.i want to search the text in the file content.any solution.if it slow might be work but at least give me solution

thanks
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 11
Reputation: wavalker is an unknown quantity at this point 
Solved Threads: 1
wavalker wavalker is offline Offline
Newbie Poster

Re: search text in a doc file

 
0
  #4
Apr 16th, 2007
Originally Posted by kapil.goyal View Post
how i can check any text string in a doc file.the searchinh should be fast as i have to do other code if it found the string
u can do one thing...

open the file/doc in input mode...
read line by line...
in every check weather ur string is present using instr(line,string)
it returns value > 0 if string is found.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 47
Reputation: kapil.goyal is an unknown quantity at this point 
Solved Threads: 0
kapil.goyal kapil.goyal is offline Offline
Light Poster

Re: search text in a doc file

 
0
  #5
Apr 16th, 2007
Originally Posted by wavalker View Post
u can do one thing...

open the file/doc in input mode...
read line by line...
in every check weather ur string is present using instr(line,string)
it returns value > 0 if string is found.
i hav tried tat logic may be my code is wrong.can u provide me the code.frm ur logic it seems tat u r not a .net programmer.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: search text in a doc file

 
0
  #6
Apr 16th, 2007
>can u provide me the code.

We do not just provide code. If you are too lazy to even try then you might as well give up programming altogether.
*Voted best profile in the world*
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: search text in a doc file

 
0
  #7
Apr 16th, 2007
Send each filename and string you want to find to this function. It will return true if the string is found and false if the string is not found.

  1. Private Function CheckFile(ByVal FileName As String, ByVal strSearch As String) As Boolean
  2. Dim s As String = My.Computer.FileSystem.ReadAllText(FileName)
  3. If InStr(s, strSearch) Then
  4. Return True
  5. Else
  6. Return False
  7. End If
  8. End Function
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 47
Reputation: kapil.goyal is an unknown quantity at this point 
Solved Threads: 0
kapil.goyal kapil.goyal is offline Offline
Light Poster

Re: search text in a doc file

 
0
  #8
Apr 17th, 2007
Originally Posted by waynespangler View Post
Send each filename and string you want to find to this function. It will return true if the string is found and false if the string is not found.

  1. Private Function CheckFile(ByVal FileName As String, ByVal strSearch As String) As Boolean
  2. Dim s As String = My.Computer.FileSystem.ReadAllText(FileName)
  3. If InStr(s, strSearch) Then
  4. Return True
  5. Else
  6. Return False
  7. End If
  8. End Function




there is no such method filesystem.readalltext in framewrok1.1.how can i read file in string format?
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 2
Reputation: kk_dj is an unknown quantity at this point 
Solved Threads: 0
kk_dj kk_dj is offline Offline
Newbie Poster

Re: search text in a doc file

 
0
  #9
Apr 26th, 2007
Originally Posted by waynespangler View Post
Send each filename and string you want to find to this function. It will return true if the string is found and false if the string is not found.

  1. Private Function CheckFile(ByVal FileName As String, ByVal strSearch As String) As Boolean
  2. Dim s As String = My.Computer.FileSystem.ReadAllText(FileName)
  3. If InStr(s, strSearch) Then
  4. Return True
  5. Else
  6. Return False
  7. End If
  8. End Function
What happen if the file size is 100 MB ?
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: search text in a doc file

 
0
  #10
Apr 27th, 2007
I don't know about 100mb you might try it. If it doesn't work then you will have to do it as wavalker said:
  1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  2. If FindStringInFile("c:\test.txt", "gooder") Then
  3. MessageBox.Show("found")
  4. Else
  5. MessageBox.Show("not found")
  6. End If
  7. End Sub
  8.  
  9. Public Function FindStringInFile(ByVal Filename As String, ByVal SearchString As String) As Boolean
  10. Dim Reader As System.IO.StreamReader
  11. Reader = New IO.StreamReader(Filename)
  12. Dim stringReader As String
  13. Try
  14. While Reader.Peek <> -1
  15. stringReader = Reader.ReadLine()
  16. If InStr(stringReader, SearchString) > 0 Then Return True
  17. End While
  18. Reader.Close()
  19. Return False
  20. Catch ex As Exception
  21. MessageBox.Show("Exception: " & ex.Message)
  22. Return False
  23. End Try
  24. End Function
Hopefully this will work in vb 2003 as I only have vb 2005.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC