"kd" <(E-Mail Removed)> schrieb im Newsbeitrag
news:9370BAF3-8703-48A6-B1A6-(E-Mail Removed)...
> Is there a command to check whether a given string is present in a text
> file, without having to read the contents of the file, a line at a time
and
> then check for the given string?
Well, you could do something like
Private Function FindInFile(ByVal searchPattern As String, ByVal path As
String) As Boolean
Dim sr As IO.StreamReader
Try
sr = New IO.StreamReader(IO.File.OpenRead(path))
Return (sr.ReadToEnd.IndexOf(searchPattern) > -1)
Catch ex As Exception
Return Nothing
Finally
sr.Close()
End Try
End Function
but I doubt that this would be faster then checking line by line and
breaking if a match occurs. That could be easily tested though...
|