| | |
search text in a doc file
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2007
Posts: 47
Reputation:
Solved Threads: 0
•
•
•
•
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
•
•
Join Date: Apr 2007
Posts: 11
Reputation:
Solved Threads: 1
•
•
•
•
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
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.
•
•
Join Date: Jan 2007
Posts: 47
Reputation:
Solved Threads: 0
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.
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
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.
VB.NET Syntax (Toggle Plain Text)
Private Function CheckFile(ByVal FileName As String, ByVal strSearch As String) As Boolean Dim s As String = My.Computer.FileSystem.ReadAllText(FileName) If InStr(s, strSearch) Then Return True Else Return False End If End Function
•
•
Join Date: Jan 2007
Posts: 47
Reputation:
Solved Threads: 0
•
•
•
•
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.
VB.NET Syntax (Toggle Plain Text)
Private Function CheckFile(ByVal FileName As String, ByVal strSearch As String) As Boolean Dim s As String = My.Computer.FileSystem.ReadAllText(FileName) If InStr(s, strSearch) Then Return True Else Return False End If End Function
there is no such method filesystem.readalltext in framewrok1.1.how can i read file in string format?
•
•
Join Date: Apr 2007
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
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.
VB.NET Syntax (Toggle Plain Text)
Private Function CheckFile(ByVal FileName As String, ByVal strSearch As String) As Boolean Dim s As String = My.Computer.FileSystem.ReadAllText(FileName) If InStr(s, strSearch) Then Return True Else Return False End If End Function
•
•
Join Date: Dec 2002
Posts: 461
Reputation:
Solved Threads: 56
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:
Hopefully this will work in vb 2003 as I only have vb 2005.
VB.NET Syntax (Toggle Plain Text)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If FindStringInFile("c:\test.txt", "gooder") Then MessageBox.Show("found") Else MessageBox.Show("not found") End If End Sub Public Function FindStringInFile(ByVal Filename As String, ByVal SearchString As String) As Boolean Dim Reader As System.IO.StreamReader Reader = New IO.StreamReader(Filename) Dim stringReader As String Try While Reader.Peek <> -1 stringReader = Reader.ReadLine() If InStr(stringReader, SearchString) > 0 Then Return True End While Reader.Close() Return False Catch ex As Exception MessageBox.Show("Exception: " & ex.Message) Return False End Try End Function
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: VB.Net Combobox Reverse Order
- Next Thread: VB.NET ComboBox & Statusbar HELP!
| Thread Tools | Search this Thread |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google gridview hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year






