title: vb.net: Encoding byte array into string using Unicode
body: <p>I am reading RAW data from a source. This raw data is a sequence of Bytes.
  I store this sequence of Bytes into an array of Bytes that I define as following in VB.NET:</p>
  
  <pre><code>Dim frame() as Byte
  </code></pre>
  
  <p>so each element in the above array is in the range [0-255].</p>
  
  <p>I want to encode each of these bytes into ASCII, UTF-8 and Unicode so I iterate over the byte array (frame) and perform below snippet code depending on the case:</p>
  
  <p><strong>ASCII</strong>:</p>
  
  <pre><code>For idxByte As Integer = 0 To Me.frame.Length - 1
      txtRefs(idxByte).Text = Encoding.ASCII.GetString(String.Format("&lt;{0}&gt;", Encoding.GetString(frame, idxByte, 1))
  Next
  </code></pre>
  
  <p>Note: txtRefs is an array of textboxes, and its length is the same as frame.</p>
  
  <p>And similar for the other two encodings:</p>
  
  <p><strong>UTF-8</strong>:</p>
  
  <pre><code>For idxByte As Integer = 0 To Me.frame.Length - 1
      txtRefs(idxByte).Text = Encoding.UTF8.GetString(String.Format("&lt;{0}&gt;", Encoding.GetString(frame, idxByte, 1))
  Next
  </code></pre>
  
  <p><strong>Unicode</strong>:</p>
  
  <pre><code>For idxByte As Integer = 0 To Me.frame.Length - 1
      txtRefs(idxByte).Text = Encoding.Unicode.GetString(String.Format("&lt;{0}&gt;", Encoding.GetString(frame, idxByte, 1))
  Next
  </code></pre>
  
  <p>ASCII and UTF8 encoding seems ok, but Unicode encoding seems it is not working or maybe I am not understanding Unicode encoding functionality at all...</p>
  
  <p>For unicode I get below <a href="http://pasteboard.co/27gtOYyy.png" rel="nofollow">result</a> by executing above loop. Is this correct?</p>