Byte conversion to string

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

Guest

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.
 
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.
 
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 ?
 
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.

newbie said:
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 ?


Daniel said:
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.
 
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?

Francois Beaussier said:
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.

--
Francois Beaussier


Daniel said:
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.
 
Back
Top