hi, im a new comer in this forum.
please anyone can help me for find string in large text file (filesize = 1mb to 5 mb)
example: i have a text document file, filename is test.txt
file test.txt contains serial number
000001
000002
000003
000004
000005
000006
000007
000008
000009
000010
The question is what is a code to find that serial number, and if not match will show message box ("Serial number not found") and if found will show message box ("Serial number found")
i also try this code but not working good, because
when i type textbox1.text = 0001
message box show "Serial number found"
i want message box show "Serial number not found" because serial number in test.txt dont have "0001"
this is the code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If FindStringInFile("c:\test.txt", textbox1.text) Then
MessageBox.Show("Serial number found")
Else
MessageBox.Show("Serial number 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
source: http://www.daniweb.com/software-development/vbnet/threads/75222/search-text-in-a-doc-file
maybe all of you guys can help me to write a correct code for what i mean.
thanks for you help and your time.