theodoros2008
Member
- Joined
- Jun 16, 2008
- Messages
- 5
- Programming Experience
- 1-3
Hi everyone.
I have a textfile with a lot data.I want to search the text for a particular string but i want to return the whole line,the line that contains the string.I got so far
Any ideas?
Thanks in advance.
I have a textfile with a lot data.I want to search the text for a particular string but i want to return the whole line,the line that contains the string.I got so far
VB.NET:
Dim svalue As String
svalue = Me.DataGridView1.SelectedCells(0).Value
If FindStringInFile(Application.StartupPath + "\oui.txt", svalue.Substring(0, 6)) Then
MessageBox.Show("found " + svalue.Substring(0, 6))
Else
MessageBox.Show("not found")
End If
VB.NET:
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
Any ideas?
Thanks in advance.