title: How to transform a byte buffer containing zeroes into a string
body: <p>I have a byte array as input. This should be the binary representation of standard conforming UTF8 HTML. It is, but most of the time only. Sometimes it also contains embedded nulls (<code>\x0</code> character or <code>NUL</code>). This is not under my control. I need to transform this byte array into a string.</p>
  
  <p>Tried so far:</p>
  
  <ul>
  <li>Obviously using a <code>StreamReader</code> or <code>TextReader</code> does not work as it stops on hitting the first <code>NUL</code></li>
  <li><code>Encoding.UTF8.GetString</code> does not work either - also stops on the first <code>NUL</code></li>
  </ul>
  
  <p>What worked but is rather unelegant:</p>
  
  <pre><code>   mynewarray = myoldarray.Where( x =&gt; x!=0).ToArray();
     var output = Encoding.UTF8.GetString(mynewarray);
  </code></pre>
  
  <p>Is there a more elegant way to do this excepted in creating a new byte array skipping the <code>NUL</code> chars and then use one of the solutions above? The byte array can be pretty big, more than 2-4 Mb... The MSDN tells that Strings might actually contain embedded <code>NUL</code> but does not tell what are the best approaches to handle such strings.</p>