PC Review


Reply
Thread Tools Rate Thread

Converting byte buffer to string

 
 
Tim Johnson
Guest
Posts: n/a
 
      29th Apr 2005
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



 
Reply With Quote
 
 
 
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      29th Apr 2005
You can use the Encoding class e.g.

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

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.peterfoot.net | www.opennetcf.org

"Tim Johnson" <(E-Mail Removed)> wrote in message
news:eK%(E-Mail Removed)...
>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
>
>
>



 
Reply With Quote
 
Tim Johnson
Guest
Posts: n/a
 
      29th Apr 2005
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


"Peter Foot [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> You can use the Encoding class e.g.
>
> string mystring = System.Text.Encoding.ASCII.GetString(mybytes)
>
> Peter
>
> --
> Peter Foot
> Windows Embedded MVP
> www.inthehand.com | www.peterfoot.net | www.opennetcf.org
>
> "Tim Johnson" <(E-Mail Removed)> wrote in message
> news:eK%(E-Mail Removed)...
>>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
>>
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting from byte to string and back to byte ends in different results? mfunkmann@yahoo.com Microsoft C# .NET 1 17th Dec 2006 02:53 PM
Converting Between byte[] and String? Matt F Microsoft C# .NET 9 28th May 2006 05:36 PM
Problem converting byte() to string and then back to byte() moondaddy Microsoft VB .NET 8 3rd May 2005 07:23 AM
Help converting Buffer of Bytes to string David Microsoft VB .NET 5 6th Apr 2005 05:39 PM
Converting Byte() to String Benoit Microsoft VB .NET 1 25th Sep 2003 04:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:31 AM.