ascii char set

D

dotnetchic

I'm trying to parse a binary file to help me with some analysis...what
I'd like to do is take a byte of data and display its ascii char value
(37='%', 38='&', etc.).

private void ParseFile(string fileName)
{
byte data;

if (File.Exists(fileName))
{
FileStream stream = new FileStream(fileName, FileMode.Open);
BinaryReader br = new BinaryReader(stream, Encoding.ASCII);

data = br.ReadByte();
// display data
}
}

How can I achieve this?

TIA,
SLC
 
J

Jon Skeet [C# MVP]

dotnetchic said:
I'm trying to parse a binary file to help me with some analysis...what
I'd like to do is take a byte of data and display its ascii char value
(37='%', 38='&', etc.).

private void ParseFile(string fileName)
{
byte data;

if (File.Exists(fileName))
{
FileStream stream = new FileStream(fileName, FileMode.Open);
BinaryReader br = new BinaryReader(stream, Encoding.ASCII);

data = br.ReadByte();
// display data
}
}

How can I achieve this?

Just cast to char. Or to convert multiple bytes at a time, use
Encoding.ASCII.GetString().
Or as you've got a BinaryReader, just use BinaryReader.ReadChars().

Jon
 
D

dotnetchic

Many thanks, Jon! I'm new to binary reader...knew there had to be a
way.

Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top