Q: Binary Data

G

Guest

Hello group,

I have a binary file that I have to read and then supply data to a client
application in readable ASCII text for storage in the database. For
instance, if the first 10 bytes of a file are:
|1|2|3|4|5|6|7|8|9|9|...

Can I turn that into a 10-character string "1234567899" without reading the
stream for 10 bytes and appending each byte into a string variable? And if
so, how?

Thanks for any light you can shed on this problem.
Richard
 
J

Jon Skeet [C# MVP]

Richard J said:
I have a binary file that I have to read and then supply data to a client
application in readable ASCII text for storage in the database. For
instance, if the first 10 bytes of a file are:
|1|2|3|4|5|6|7|8|9|9|...

Can I turn that into a 10-character string "1234567899" without reading the
stream for 10 bytes and appending each byte into a string variable? And if
so, how?

The most common way of turning arbitrary binary data into ASCII text is
to use Base64. You can stream this using the crypto transforms
"ToBase64Transform" and "FromBase64Transform".
 

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