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 / January 2006

Tip: Looking for answers? Try searching our database.

Byte conversion to string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel - 11 Jan 2006 03:49 GMT
I can't seem to find any byte array conversion functions to strings.
I'm receiving data via a network packet and want to convert the byte array
contents into there actual character equivilent.

For example
Convert
byte[] byteArray = { 64, 65, some ascii numbers }
To
char[] charArray = { A, B, some characters }
by the way I don't think my ascii numbers are correct

In C++ you would just typecast them but I can't seem to do that.
Francois Beaussier - 11 Jan 2006 04:36 GMT
Hello Daniel,

you can use the following method:

string myStr = System.Text.Encoding.ASCII.GetString(byteArray);

You can use others encoding depending on your needs.

Signature

Francois Beaussier

>I can't seem to find any byte array conversion functions to strings.
> I'm receiving data via a network packet and want to convert the byte array
[quoted text clipped - 8 lines]
>
> In C++ you would just typecast them but I can't seem to do that.
Daniel - 11 Jan 2006 22:23 GMT
This works well
I knew there had to be a solution somewhere!!!
Navigating the docs to find this isn't easy how did you find out about it?

> Hello Daniel,
>
[quoted text clipped - 16 lines]
> >
> > In C++ you would just typecast them but I can't seem to do that.
Francois Beaussier - 11 Jan 2006 22:30 GMT
> Navigating the docs to find this isn't easy how did you find out about it?

hum, I can't remember where I got that one :)

Signature

Francois Beaussier

newbie - 11 Jan 2006 08:41 GMT
you want a conversion from the acii numbers to the characters ?
like chr(32) / returns  space
chr(33)   /returns !
chr(65)  /returns A

asc("A") / returns 65
asc(" ") /returns 32

Make a  for next loop and convert your array ?

>I can't seem to find any byte array conversion functions to strings.
> I'm receiving data via a network packet and want to convert the byte array
[quoted text clipped - 8 lines]
>
> In C++ you would just typecast them but I can't seem to do that.
Daniel - 11 Jan 2006 22:21 GMT
This solution works also but I think the other solution is better for my
purposes just because it converts the whole array at once.  

Thanks for your input though I can see where I would use this tecnique over
the other one.

> you want a conversion from the acii numbers to the characters ?
> like chr(32) / returns  space
[quoted text clipped - 18 lines]
> >
> > In C++ you would just typecast them but I can't seem to do that.

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.