• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

Visual Basic - How to convert a Byte() array to a string

I am constrained by the library I am using to read a text file in as a binary.  I would like to be able to convert the binary array into a string.  What is the best way?

Dim binfile As Byte() = srcFile.OpenBinary
statusBox.text = srcFileAsString
1 Solution
Todd MummertCommented:

depends on the encoding (ASCII, UNICODE, UTF, etc)

if unicode

Private Function UnicodeBytesToString( _
    ByVal bytes() As Byte) _
    As String

    Return System.Text.Encoding.Unicode.GetString(bytes)
End Function

see here:  http://msdn.microsoft.com/en-us/library/ms172827(VS.80).aspx

for the other formats such as
TedgClAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now