Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

StreamReader problems with BaseStream Position

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ferreira - 04 Mar 2006 22:37 GMT
Hi,

I'm creating a class to read some text datafiles.

These files start with a header with variable length, followed by a section
with data values (numbers in separate lines) also with variable length. The
data section must be read sequentialy, so my approch to this is:

-Read the header (line by line) until find the header's end.
-Store the Position of the BaseStream property of the StreamReader
-Read the data section (also line by line)

I need to store the stream position before start reading the data section,
to be able to re-read the data without having to parse the header again.

The problem is that the StreamReader buffers data, so the value returned in
BaseStream.Position property is always ahead of the actual processed line.

I understand that we need to call DiscardBufferedData after seeking in the
base stream, so we start to read in the right position.

But how can I know the exact position, discarding the buffered data that was
not returned in the ReadLine method?

Any other way to make this?

Thanks!
Jon Skeet [C# MVP] - 05 Mar 2006 08:23 GMT
> I'm creating a class to read some text datafiles.
>
[quoted text clipped - 17 lines]
> But how can I know the exact position, discarding the buffered data that was
> not returned in the ReadLine method?

I'm afraid you can't, as far as I know. If the file is encoded in a
text encoding which is fixed-width, you could keep track of how much
text has been read and multiply that by the width, but that's the only
solution I know of :(

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

ferreira - 05 Mar 2006 15:46 GMT
Hi,

Thanks for your reply.

The files are ASCII encoded, so the method you pointed works and is also
very simple :)

Thanks for the suggestion!

Pedro

> > I'm creating a class to read some text datafiles.
> >
[quoted text clipped - 22 lines]
> text has been read and multiply that by the width, but that's the only
> solution I know of :(

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.