R
Rico
In the following piece of code:
*******************************************************
byte[] buffer = new byte[20];
string next_node=null, ret=null;
ASCIIEncoding encoding = new ASCIIEncoding();
BufferedStream sr = new BufferedStream (new FileStream (nodeptr, FileMode.Open ));
sr.Seek(6, SeekOrigin.Begin );
sr.Read (buffer, 0, 17);
next_node = encoding.GetString(buffer);
Console.WriteLine(next_node.Trim() + "__");
*******************************************************
I read 17 bytes from a text file as from the 7th byte onwards.
Why is it that the final WriteLine statement shows what appears to be
characters with ASCII code 0 in next_node before the "__" ?
A work-around is to set the size of buffer to exactly the number of bytes
I happen to know I need to read. What when I don't and overallocate space
in buffer, or when Read() says fewer bytes than requested were read and I
only want to convert those to a string?
Rico.
*******************************************************
byte[] buffer = new byte[20];
string next_node=null, ret=null;
ASCIIEncoding encoding = new ASCIIEncoding();
BufferedStream sr = new BufferedStream (new FileStream (nodeptr, FileMode.Open ));
sr.Seek(6, SeekOrigin.Begin );
sr.Read (buffer, 0, 17);
next_node = encoding.GetString(buffer);
Console.WriteLine(next_node.Trim() + "__");
*******************************************************
I read 17 bytes from a text file as from the 7th byte onwards.
Why is it that the final WriteLine statement shows what appears to be
characters with ASCII code 0 in next_node before the "__" ?
A work-around is to set the size of buffer to exactly the number of bytes
I happen to know I need to read. What when I don't and overallocate space
in buffer, or when Read() says fewer bytes than requested were read and I
only want to convert those to a string?
Rico.