title: Are null terminators part of text encoding?
body: <p>I'm trying to read a null terminated string from a byte array; the parameter to the function is the encoding.</p>
  
  <pre><code>string ReadString(Encoding encoding)
  </code></pre>
  
  <p>For example, "foo" in the following encodings are:</p>
  
  <pre><code>UTF-32: 66 00 00 00 6f 00 00 00 6f 00 00 00
  UTF-8:  66 6f 6f
  UTF-7:  66 6f 6f 2b 41 41 41 2d
  </code></pre>
  
  <p>If I copied all the bytes into an array (reading up to the null terminator) and passed that array into <code>encoding.GetString()</code>, it wouldn't work because if the string was UTF-32 encoded my algorithm would reach the "null terminator" after the second byte.</p>
  
  <p>So I sort of have a double question: Are null terminators part of the encoding? If not, how could I decode the string character by character and check the following byte for the null terminator?</p>
  
  <p>Thanks in advance</p>
  
  <p>(suggestions are also appreciated)</p>
  
  <p>Edit:</p>
  
  <p>If "foo" was null terminated and utf-32 encoded, which would it be?:</p>
  
  <pre><code>1. 66 00 00 00 6f 00 00 00 6f 00 00 00   00
  2. 66 00 00 00 6f 00 00 00 6f 00 00 00   00 00 00 00
  </code></pre>