ReadString method (BinaryReader class)

  • Thread starter Thread starter liljester
  • Start date Start date
L

liljester

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
 
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
 
liljester said:
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.
 
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.
 
Back
Top