Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2005

Tip: Looking for answers? Try searching our database.

How to convert Byte[] into String?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
EOS - 02 Dec 2005 18:14 GMT
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. : )
Mattias Sjögren - 02 Dec 2005 18:38 GMT
>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

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

EOS - 02 Dec 2005 19:49 GMT
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
balmerch - 02 Dec 2005 20:16 GMT
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.
>
[quoted text clipped - 17 lines]
> >
> > Mattias
EOS - 02 Dec 2005 20:23 GMT
I think it does not work on compact .net framework as the compilier error
show "No overload for method 'GetString' takes '1'1 arguments"

>I don't know if this is in the compact framework but try:
>
[quoted text clipped - 27 lines]
>> >
>> > Mattias
balmerch - 02 Dec 2005 20:35 GMT
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

> I think it does not work on compact .net framework as the compilier error
> show "No overload for method 'GetString' takes '1'1 arguments"
[quoted text clipped - 30 lines]
> >> >
> >> > Mattias
EOS - 03 Dec 2005 08:31 GMT
Thanks! It is working now. : )

> Try this method signature then:
>
[quoted text clipped - 40 lines]
>> >> >
>> >> > Mattias

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.