How to convert Byte[] into String?

E

EOS

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. : )
 
M

Mattias Sjögren

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
 
E

EOS

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 said:
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
 
G

Guest

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 said:
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 said:
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
 
E

EOS

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 said:
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 said:
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 said:
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
 
G

Guest

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 said:
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 said:
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 said:
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?


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
 
E

EOS

Thanks! It is working now. : )

balmerch said:
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 said:
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 said:
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

:

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?


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
 

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