PC Review


Reply
Thread Tools Rate Thread

How to convert Byte[] into String?

 
 
EOS
Guest
Posts: n/a
 
      2nd Dec 2005
Hi,

I would like to ask on how to convert array of bytes, Byte[] into String?

I tried StringIwant = System.Convert.ToString(byteData);

but it actually return "System.Byte[]" rather than convert the data I wanted
into string.

I guess it should be a rather simple question.

By the way, I am using compact framework for PDA.

Thanks in advance. : )


 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      2nd Dec 2005

>I would like to ask on how to convert array of bytes, Byte[] into String?


Use System.Text.Encoding (or one of the classes derived from it).
Which encoding to use depends on what's on your byte array.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
EOS
Guest
Posts: n/a
 
      2nd Dec 2005
I think it does not work.

Actually what I wanted is rather simple.

In C/C++, it is;

byte byteData[500] = .....

CString szMyString = (CString) byteData

It is that simple and straight forward because what is inside the byte array
is exactly the same char[]. Even a simple memcpy will work.

Any ideas on how to implement these simple object convertion?

"Mattias Sjögren" <(E-Mail Removed)> wrote in message
news:eiDpD$(E-Mail Removed)...
>
>>I would like to ask on how to convert array of bytes, Byte[] into String?

>
> Use System.Text.Encoding (or one of the classes derived from it).
> Which encoding to use depends on what's on your byte array.
>
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.



 
Reply With Quote
 
=?Utf-8?B?YmFsbWVyY2g=?=
Guest
Posts: n/a
 
      2nd Dec 2005
I don't know if this is in the compact framework but try:

ASCIIEncoding.ASCII.GetString( myByteArray);

Make sure you include the System.Text namespace ("using System.Text;").

Chris

"EOS" wrote:

> I think it does not work.
>
> Actually what I wanted is rather simple.
>
> In C/C++, it is;
>
> byte byteData[500] = .....
>
> CString szMyString = (CString) byteData
>
> It is that simple and straight forward because what is inside the byte array
> is exactly the same char[]. Even a simple memcpy will work.
>
> Any ideas on how to implement these simple object convertion?
>
> "Mattias Sjögren" <(E-Mail Removed)> wrote in message
> news:eiDpD$(E-Mail Removed)...
> >
> >>I would like to ask on how to convert array of bytes, Byte[] into String?

> >
> > Use System.Text.Encoding (or one of the classes derived from it).
> > Which encoding to use depends on what's on your byte array.
> >
> >
> > Mattias
> >
> > --
> > Mattias Sjögren [C# MVP] mattias @ mvps.org
> > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> > Please reply only to the newsgroup.

>
>
>

 
Reply With Quote
 
EOS
Guest
Posts: n/a
 
      2nd Dec 2005
I think it does not work on compact .net framework as the compilier error
show "No overload for method 'GetString' takes '1'1 arguments"

"balmerch" <(E-Mail Removed)> wrote in message
news:6B146126-5D4C-457A-AB4D-(E-Mail Removed)...
>I don't know if this is in the compact framework but try:
>
> ASCIIEncoding.ASCII.GetString( myByteArray);
>
> Make sure you include the System.Text namespace ("using System.Text;").
>
> Chris
>
> "EOS" wrote:
>
>> I think it does not work.
>>
>> Actually what I wanted is rather simple.
>>
>> In C/C++, it is;
>>
>> byte byteData[500] = .....
>>
>> CString szMyString = (CString) byteData
>>
>> It is that simple and straight forward because what is inside the byte
>> array
>> is exactly the same char[]. Even a simple memcpy will work.
>>
>> Any ideas on how to implement these simple object convertion?
>>
>> "Mattias Sjögren" <(E-Mail Removed)> wrote in message
>> news:eiDpD$(E-Mail Removed)...
>> >
>> >>I would like to ask on how to convert array of bytes, Byte[] into
>> >>String?
>> >
>> > Use System.Text.Encoding (or one of the classes derived from it).
>> > Which encoding to use depends on what's on your byte array.
>> >
>> >
>> > Mattias
>> >
>> > --
>> > Mattias Sjögren [C# MVP] mattias @ mvps.org
>> > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
>> > Please reply only to the newsgroup.

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?YmFsbWVyY2g=?=
Guest
Posts: n/a
 
      2nd Dec 2005
Try this method signature then:

ASCIIEncoding.ASCII.GetString( myByteArray, 0, myByteArray.Length );

There are 2 method signatures for it on the full framework, since the first
isn't available on the CF, I assume the second must be.

Chris

"EOS" wrote:

> I think it does not work on compact .net framework as the compilier error
> show "No overload for method 'GetString' takes '1'1 arguments"
>
> "balmerch" <(E-Mail Removed)> wrote in message
> news:6B146126-5D4C-457A-AB4D-(E-Mail Removed)...
> >I don't know if this is in the compact framework but try:
> >
> > ASCIIEncoding.ASCII.GetString( myByteArray);
> >
> > Make sure you include the System.Text namespace ("using System.Text;").
> >
> > Chris
> >
> > "EOS" wrote:
> >
> >> I think it does not work.
> >>
> >> Actually what I wanted is rather simple.
> >>
> >> In C/C++, it is;
> >>
> >> byte byteData[500] = .....
> >>
> >> CString szMyString = (CString) byteData
> >>
> >> It is that simple and straight forward because what is inside the byte
> >> array
> >> is exactly the same char[]. Even a simple memcpy will work.
> >>
> >> Any ideas on how to implement these simple object convertion?
> >>
> >> "Mattias Sjögren" <(E-Mail Removed)> wrote in message
> >> news:eiDpD$(E-Mail Removed)...
> >> >
> >> >>I would like to ask on how to convert array of bytes, Byte[] into
> >> >>String?
> >> >
> >> > Use System.Text.Encoding (or one of the classes derived from it).
> >> > Which encoding to use depends on what's on your byte array.
> >> >
> >> >
> >> > Mattias
> >> >
> >> > --
> >> > Mattias Sjögren [C# MVP] mattias @ mvps.org
> >> > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> >> > Please reply only to the newsgroup.
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
EOS
Guest
Posts: n/a
 
      3rd Dec 2005
Thanks! It is working now. : )

"balmerch" <(E-Mail Removed)> wrote in message
news:EF1C2F38-AAD2-4B80-A659-(E-Mail Removed)...
> Try this method signature then:
>
> ASCIIEncoding.ASCII.GetString( myByteArray, 0, myByteArray.Length );
>
> There are 2 method signatures for it on the full framework, since the
> first
> isn't available on the CF, I assume the second must be.
>
> Chris
>
> "EOS" wrote:
>
>> I think it does not work on compact .net framework as the compilier error
>> show "No overload for method 'GetString' takes '1'1 arguments"
>>
>> "balmerch" <(E-Mail Removed)> wrote in message
>> news:6B146126-5D4C-457A-AB4D-(E-Mail Removed)...
>> >I don't know if this is in the compact framework but try:
>> >
>> > ASCIIEncoding.ASCII.GetString( myByteArray);
>> >
>> > Make sure you include the System.Text namespace ("using System.Text;").
>> >
>> > Chris
>> >
>> > "EOS" wrote:
>> >
>> >> I think it does not work.
>> >>
>> >> Actually what I wanted is rather simple.
>> >>
>> >> In C/C++, it is;
>> >>
>> >> byte byteData[500] = .....
>> >>
>> >> CString szMyString = (CString) byteData
>> >>
>> >> It is that simple and straight forward because what is inside the byte
>> >> array
>> >> is exactly the same char[]. Even a simple memcpy will work.
>> >>
>> >> Any ideas on how to implement these simple object convertion?
>> >>
>> >> "Mattias Sjögren" <(E-Mail Removed)> wrote in message
>> >> news:eiDpD$(E-Mail Removed)...
>> >> >
>> >> >>I would like to ask on how to convert array of bytes, Byte[] into
>> >> >>String?
>> >> >
>> >> > Use System.Text.Encoding (or one of the classes derived from it).
>> >> > Which encoding to use depends on what's on your byte array.
>> >> >
>> >> >
>> >> > Mattias
>> >> >
>> >> > --
>> >> > Mattias Sjögren [C# MVP] mattias @ mvps.org
>> >> > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
>> >> > Please reply only to the newsgroup.
>> >>
>> >>
>> >>

>>
>>
>>



 
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
Convert Byte() <-> String Bob Altman Microsoft VB .NET 6 24th Jun 2008 03:47 AM
How to convert a String into Byte[] EOS Microsoft C# .NET 5 5th Dec 2005 05:46 AM
How to convert a byte() to string Dean Slindee Microsoft VB .NET 4 17th Oct 2005 06:00 PM
How to convert byte() to string, and from string back to byte() moondaddy Microsoft VB .NET 4 15th Aug 2005 03:25 PM
How Do I: convert a String to Byte[] Russell Mangel Microsoft Dot NET 3 14th Dec 2003 03:51 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:39 AM.