Monday, June 2, 2008

How to Convert Byte Array into String

Level: Beginner

Knowlege Required:
  • Text Encoding
  • String
  • Array
Sometimes it is required to convert the byte Array into String. For example if we have read the bytes from some Stream (like reading a file or getting data from port) then we may need to convert that Byte Array into String so we can display it somewhere.

For this purpose we use Text Encoding:

StringVariable = System.Text.Encoding.ASCII.GetString(byte array)

Dim b(5) As Byte

b(0) = 65
b(1) = 66
b(2) = 67
b(3) = 68
b(4) = 69


Output will be:

See Also:

How to Convert String into Byte Array

No comments: