Convert byte array to string?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I'm trying to convert a byte array to string

--This works...
System.BitConverter.ToString(bytes)

"EB-55-79-20-18-B2-76-4D-85-0A-93-6B-97-33-31-B8"

--This doesn't, but returns "System.Byte[]". How do I do this with
System.Convert.ToString()???

System.Convert.ToString(bytes)
"System.Byte[]"
 
Dave,

You can't. When you pass the array to the ToString method, it considers
it an object, at which point, it calls the ToString method of the object
passed in. For an array, it just returns the type name.

You will have to use the BitConverter to get a string of bytes.

Hope this helps.
 
Try out
System.Text.Encoding.ASCII.GetString
or System.Text.Encoding.Unicode.GetString
methods. It depends upon Encoding (ASCII or Unicode) you are using.

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net
 
I'm still a novice myself, but you might try:

string tempString = "";

tempString = byteArray.ToString();

I think that might solve your problem. Good luck. I'm having the opposite problem. I'm trying to stuff a string into a byte.

*****************************************
* A copy of the whole thread can be found at:
* http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-csharp/27613
*
* Report spam or abuse by clicking the following URL:
* http://www.dotnetmonster.com/Uwe/Abuse.aspx?aid=95d36f1542db46438c51673a8ebd5ba9
*****************************************
 
Back
Top