C
chrisben
Hi,
I have a binary reader which read a stream from the network through
MemoryStream, the data in the stream is a 8 bytes char array. it could be a
string with 2 chars to 7 chars. it is garanteed that there will be a
terminator at the end of the string, but there could be garbage to fill the
rest of the array.
For example, the array could be {'a','b','\0', ....}
I use CharToString (reader.ReadChars(8)) to get the data. However, it seems
work only if the rest of array is all filled with terminators. Otherwise,
will get overflow error. As I already have one terminator after the string, I
do not want to fill the rest of the array by initialization. Seems ReadChars
not working in this case, is there other method in C# that I should use to
read string correctly?
Thanks
Chris
I have a binary reader which read a stream from the network through
MemoryStream, the data in the stream is a 8 bytes char array. it could be a
string with 2 chars to 7 chars. it is garanteed that there will be a
terminator at the end of the string, but there could be garbage to fill the
rest of the array.
For example, the array could be {'a','b','\0', ....}
I use CharToString (reader.ReadChars(8)) to get the data. However, it seems
work only if the rest of array is all filled with terminators. Otherwise,
will get overflow error. As I already have one terminator after the string, I
do not want to fill the rest of the array by initialization. Seems ReadChars
not working in this case, is there other method in C# that I should use to
read string correctly?
Thanks
Chris