473,485 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Convert byte array to string?

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[]"
Nov 16 '05 #1
8 39912
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
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[]"

Nov 16 '05 #2
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
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/For...t-csharp/27613
*
* Report spam or abuse by clicking the following URL:
* http://www.dotnetmonster.com/Uwe/Abu...51673a8ebd5ba9
*****************************************
Nov 16 '05 #4
Simple ToString method will not work. Use the System.Text.Encoding class:

System.Text.Encoding.<ENCODER_NAME>.GetString()

Michael

*****************************************
* A copy of the whole thread can be found at:
* http://www.dotnetmonster.com/Uwe/For...t-csharp/27613
*
* Report spam or abuse by clicking the following URL:
* http://www.dotnetmonster.com/Uwe/Abu...9f620b6fb71687
*****************************************
Nov 16 '05 #5
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/For...t-csharp/27613
*
* Report spam or abuse by clicking the following URL:
* http://www.dotnetmonster.com/Uwe/Abu...51673a8ebd5ba9
*****************************************
Nov 16 '05 #6
Simple ToString method will not work. Use the System.Text.Encoding class:

System.Text.Encoding.<ENCODER_NAME>.GetString()

Michael

*****************************************
* A copy of the whole thread can be found at:
* http://www.dotnetmonster.com/Uwe/For...t-csharp/27613
*
* Report spam or abuse by clicking the following URL:
* http://www.dotnetmonster.com/Uwe/Abu...9f620b6fb71687
*****************************************
Nov 16 '05 #7
Use GetBytes instead of GetString method.

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #8
Use GetBytes instead of GetString method.

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4435
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
6
10126
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
15
34561
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
6
12741
by: Allan Ebdrup | last post by:
How do I easily convert a int to a string? Kind Regards, Allan Ebdrup
6
53667
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
6
5235
by: Bob Altman | last post by:
Hi all, I'm looking for the fastest way to convert an array of bytes to String. I also need to convert a String back to its original Byte() representation. Convert.ToBase64String and...
12
13504
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
19
5304
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
5
4811
by: da1978 | last post by:
Hi experts, I need to convert a string or a Byte array to a string byte array. Its relatively easy to convert a string to an char array or a byte array but not a STRING byte array. i.e. ...
0
10704
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
6960
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7116
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6825
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7275
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4857
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4551
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1376
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
595
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.