c# - Pattern search in a System.IO.Stream -


i receiving system io streams source. proceed stream object if contains string "mstnd".

i realize there not can on stream unless convert string. string conversion sub-string matching. don't want takes lot of time or space. how time / space intensive conversion stream string sub-string matching?

the code have written is:

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 ; } 

depending on in stream you're expecting sequence efficient convert string perform substring. if in standard spot each time can read through number of bytes required , convert them string.

take @ reference: http://msdn.microsoft.com/en-us/library/system.io.stream.read.aspx

alternatively convert string "mstnd" byte[] , search stream byte[].

edit:

i found how consistent byte representation of strings in c# without manually specifying encoding? should converting string byte[].


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -