all groups > vb.net > february 2004 >
You're in the

vb.net

group:

Finding string in text file


Re: Finding string in text file Jay B. Harlow [MVP - Outlook]
2/29/2004 5:17:04 PM
vb.net: Phil,
You can use StreamReader.ReadToEnd to read the entire string. Then you can
use String.IndexOf to find the string.

Just be mindful of large files, reading the entire file into memory at once
can put undue pressure on the GC...

[quoted text, click to view]
No

Hope this helps
Jay

[quoted text, click to view]

Finding string in text file Phil
2/29/2004 9:36:32 PM
Hi,

Is there a 'shorter' way to find a string within a text file without
'testing' each character or using the LineInput function. Does the
StreamReader have any search facility?

Thanks,

Phil

Re: Finding string in text file hirf-spam-me-here NO[at]SPAM gmx.at
2/29/2004 11:43:04 PM
* "Phil" <Phil@nospam.com> scripsit:
[quoted text, click to view]

You can read the file line by line and use the line's 'IndexOf' method
to find the string.

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Re: Finding string in text file hirf-spam-me-here NO[at]SPAM gmx.at
2/29/2004 11:54:11 PM
Addendum:

Ooops... Pressed send keys instead of pasting code:

Basic code for reading the lines of a file:

\\\
Imports System.IO
..
..
..
Dim sr As New StreamReader("C:\WINDOWS\WIN.INI")
Dim strLine As String
strLine = sr.ReadLine()
Do Until strLine Is Nothing
MsgBox(strLine)
strLine = sr.ReadLine()
Loop
sr.Close()
///

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Re: Finding string in text file Phil
3/1/2004 9:55:34 PM
Thanks to Jay and Herfried. I will look into the .IndexOf method.

Have a great week.

Phil

[quoted text, click to view]

AddThis Social Bookmark Button