I get System IO streams from the source. I will continue to stream object only if it contains a string "MSTND".
I understand that there is little that can be done in the stream if I do not convert it to a string. String conversion is for substring only. But I do not want to do anything that takes a lot of time or space. How is time / space intensity converting from Stream to string just for substring matching?
The code I wrote 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 ;
}
source
share