|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Simple (I hope) SteamReader DirectoryInfo questionWhen I step through the following code snippet: Dim di As DirectoryInfo = New DirectoryInfo(strMyPath) Dim sr As StreamReader If di.Exists Then Dim fi As FileInfo For Each fi In di.GetFiles("*.txt") sr = fi.OpenText() Dim SomeText As String SomeText = sr.ReadToEnd() If sr.ReadToEnd().ToUpper.IndexOf("mytext") > 0 Then MsgBox("success") End If Next fi If I put a break point on the "SomeText = sr.ReadToEnd()" line and view the value of sr.ReadToEnd it says "" (empty string). However, on the same breakpoint fi.OpenText().ReadToEnd shows me "mytext". As you can see, I set "sr = fi.OpenText()" a couple lines about the "SomeText = sr.ReadToEnd()" line. Any idea what's going on? Thanks, Eric eric.gofo***@gmail.com wrote:
Show quoteHide quote > Hello, check what the length of the string is. There are some characters > > When I step through the following code snippet: > > Dim di As DirectoryInfo = New DirectoryInfo(strMyPath) > Dim sr As StreamReader > > If di.Exists Then > > Dim fi As FileInfo > For Each fi In di.GetFiles("*.txt") > sr = fi.OpenText() > Dim SomeText As String > SomeText = sr.ReadToEnd() > If sr.ReadToEnd().ToUpper.IndexOf("mytext") > 0 > Then > MsgBox("success") > End If > Next fi > > If I put a break point on the "SomeText = sr.ReadToEnd()" line and view > the value of sr.ReadToEnd it says "" (empty string). However, on the > same breakpoint fi.OpenText().ReadToEnd shows me "mytext". As you can > see, I set "sr = fi.OpenText()" a couple lines about the "SomeText = > sr.ReadToEnd()" line. Any idea what's going on? > > Thanks, > Eric > ("/0") that will make the string thing it's come to the end when you display it in debug session. You could do something like: do while sr isnot nothing sr = fi.readline debug.writeline(sr) loop Also you can not do ReadToEnd twice. Once you readtoend, you are at the end of the file and can not do a read again. Change your second read to: If SomeText.ToUpper.IndexOf("mytext") > 0 Then Why do you do a ToUpper but then check it against a lower case string? Also, you may want to add a fi.Close before your "next fi" statement. Chris Never mind, this was just one of those goofy my app didn't recompile
things. Thanks, Eric
Query Builder
Cancel a thread - please help Dataset requery Permutation listing Tell to ASP.Net don't watch some web folders Assigning ListBox Current Selection to TextBox multiple tcp connections FileSystemObject filter? File Info Question extracting part of a graphic in a PictureBox to the clipboard |
|||||||||||||||||||||||