Converting byte buffer to string

T

Tim Johnson

I have to read an ASCIIZ byte buffer from a registry entry and display it on
my form. What's the right way to convert this to a C# string? I can see
the bytes as an object retrieved from the OpenNETCF registry, as in "0x41
0x42 0x43 0x00". I was hoping there was a simple convert statement, vs.
some roundabout way using a TextReader stream or something.

--

Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625
 
P

Peter Foot [MVP]

You can use the Encoding class e.g.

string mystring = System.Text.Encoding.ASCII.GetString(mybytes)

Peter
 
T

Tim Johnson

That was it, thanks (although for some reason I needed to specify the
start/length parameters, it complained about having only 1 parameter even
though the help says that legitimate).

--

Tim Johnson
High Point Software, Inc.
www.high-point.com
(503) 312-8625
 

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