PC Review


Reply
Thread Tools Rate Thread

How do I read interspersed blank lines (CrLf) using streams?

 
 
Larry Woods
Guest
Posts: n/a
 
      31st Aug 2003
I have a seq. file with some blank lines (CrLf only) in it. When the line
is read, I get a value of "Nothing" returned, which give me an "End of File"
condition, so I terminate my procedure.

How do you get around interspersed blank lines?

TIA,

Larry Woods


 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      31st Aug 2003
Larry,

>I have a seq. file with some blank lines (CrLf only) in it. When the line
>is read, I get a value of "Nothing" returned, which give me an "End of File"
>condition, so I terminate my procedure.


You probably have code similar to this

Dim line As String = yourStreamReader.ReadLine()
Do Until line = Nothing
...
line = yourStreamReader.ReadLine()
Loop

The problem is that (line = Nothing) evaluates to True for empty
strings as well. Change it to

Do Until line Is Nothing



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
 
Reply With Quote
 
Larry Woods
Guest
Posts: n/a
 
      31st Aug 2003
You are soooo right. Thanks much. Any possibility you could give me a hint
on where I would have found that in the VB doc? I "thought" that I had
looked everywhere!

TIA,

Larry Woods

"Mattias Sjögren" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Larry,
>
> >I have a seq. file with some blank lines (CrLf only) in it. When the

line
> >is read, I get a value of "Nothing" returned, which give me an "End of

File"
> >condition, so I terminate my procedure.

>
> You probably have code similar to this
>
> Dim line As String = yourStreamReader.ReadLine()
> Do Until line = Nothing
> ...
> line = yourStreamReader.ReadLine()
> Loop
>
> The problem is that (line = Nothing) evaluates to True for empty
> strings as well. Change it to
>
> Do Until line Is Nothing
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/
> Please reply only to the newsgroup.



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      31st Aug 2003
Hello,

"Larry Woods" <(E-Mail Removed)> schrieb:
> I have a seq. file with some blank lines (CrLf only) in it.
> When the line is read, I get a value of "Nothing" returned,
> which give me an "End of File" condition, so I terminate
> my procedure.
>
> How do you get around interspersed blank lines?


\\\
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()
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      31st Aug 2003
Hi Larry,

Nothing is not just the equivalent of a null pointer. It means the default
value for the type in question.

In the case of an object that will be a null pointer. Strings, however,
while being objects, are treated as a special case.

|| if sSomeString = Nothing

The sSomeString in this context is the string contents and the Nothing is
the default for string contents, ie "".

|| if sSomeStringVar Is Nothing

The sSomeStringVar in this context is the pointer to string contents and
the Nothing is the default for objects which is null pointer.

To have understood this you would have had to have read the sections on
Nothing, Strings, Expressions and a couple of other topics, I'm sure. You may
well have read all these areas, but often an understanding of any one help
topic relies on making connections from other topics, plus a bit of fiddling
about with code, plus a bit of asking other people. Which you've just done.
:-)

Regards,
Fergus


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 03 puts extra blank lines between Signature Lines when Rep =?Utf-8?B?RGF3ZWI=?= Microsoft Outlook Discussion 0 4th Apr 2005 05:41 PM
How to write and read from streams (Istream) Save webpage as Image =?Utf-8?B?cHJha2FzaA==?= Microsoft VC .NET 0 21st Feb 2005 05:07 AM
Using streams how do I write and then read a set of variables Just Me Microsoft VB .NET 5 19th Jan 2005 05:09 AM
how to automatically insert blank lines in between non-blank lines Microsoft Excel Programming 2 17th Nov 2003 03:40 PM
Unable to read security descriptors data streams Steve Windows XP Hardware 1 4th Sep 2003 01:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:14 PM.