How to convert Byte[] into String?

  • Thread starter Thread starter EOS
  • Start date Start date
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. : )
 
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
 
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
 
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
 
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
 
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
 
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
 
Back
Top