title: Pattern search in a System.IO.Stream
body: <p>I am receiving System IO Streams from a source. I will proceed with the stream object only if it contains the string <code>"MSTND"</code>. </p>
  
  <p>I realize there is not much I can do on the stream unless I convert it into string. The string conversion is only for sub-string matching. But I don't want to do anything that takes up lot of time or space. How time / space intensive is a conversion from Stream to string just for sub-string matching?</p>
  
  <p>The code I have written is:</p>
  
  <pre><code>private bool StreamHasString (Stream vStream)
  {
       bool containsStr = false;
       byte[] streamBytes = new byte[vStream.Length];
       vStream.Read( streamBytes, 0, (int) vStream.Length);
       string stringOfStream = Encoding.UTF32.GetString(streamBytes);
       if (stringOfStream.Contains("MSTND"))
       {
          containsStr = true;
       }     
       return containsStr ;
  }
  </code></pre>