Reading an ASCII string from a binaryreader

  • Thread starter Thread starter Claire
  • Start date Start date
C

Claire

Would someone give me a code example that reads an ASCII string from a
binary reader and converts it to a c# string please. I find that the help
files aren't very clear on how do do this eg "DATA" = 4 bytes 0x44,
0x41,0x54,0x41
 
Hi Claire,

You need to read the ASCII data into a byte array, then using

string s = Encoding.ASCII.GetString(byte array)
 
hi,

Depending of the binary file's structure you could decorate the binary
reader with a streamreader.

cheers,
 
Claire said:
Would someone give me a code example that reads an ASCII string from a
binary reader and converts it to a c# string please. I find that the help
files aren't very clear on how do do this eg "DATA" = 4 bytes 0x44,
0x41,0x54,0x41

Call the constructor for BinaryReader which takes an Encoding, then
call BinaryReader.ReadChars, specifying how many you wish to read.
 
Back
Top