471,089 Members | 1,274 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

ReadString method (BinaryReader class)

Is there a way to tell this method how many bytes to read
from the stream? the msdn documentation doesnt explain
its usage very well...

Any help would be much appreciated
Nov 15 '05 #1
3 6975
Is there a way to tell this method how many bytes to read
from the stream? the msdn documentation doesnt explain
its usage very well...


BinaryReader.ReadString should be used to read strings written with
BinaryWriter.WriteString (or something that uses the same format).
They are length prefixed, so the reader knows how much to read.

If you just have a sequence of characters that you know the length of,
use the ReadChars method instead.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #2
liljester <an*******@discussions.microsoft.com> wrote:
Is there a way to tell this method how many bytes to read
from the stream?
No - it knows automatically how much to read.
the msdn documentation doesnt explain
its usage very well...


I think it explains what it does fairly well. It reads the 7-bit-
encoded length (see BinaryReader.Write7BitEncodedInt for details), and
then reads that many bytes from the stream, and then decodes them.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
<an*******@discussions.microsoft.com> wrote:
thank you mattias and jon, i had no idea what the
explaination was talking about.

jon- it isnt much of an explaination for a beginning c#
programmer that has never used the binary reader class.


It's got nothing to do with C# though. It's pretty much self-contained.
The only bit of nous it takes is working out that the "encoded as an
integer seven bits at a time" probably related to the
"Read7BitEncodedInt" method.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Question with BinaryReader | last post: by
1 post views Thread by JimM | last post: by
4 posts views Thread by David Compton | last post: by
5 posts views Thread by Laurel | last post: by
3 posts views Thread by =?Utf-8?B?VmljdG9y?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.