如何修剪流C#

时间:2017-05-23 14:38:49

标签: c# stream gzip trim gzipstream

string hexstr = http.Body.ToString();
if (hexstr.Contains("1f8b"))
{
    Stream str = http.Body.ToMemoryStream();
    str.Position = str.Seek(0x1f8b, SeekOrigin.Begin);
    using (var zipStream = new GZipStream(str, CompressionMode.Decompress))
    using (var resultStream = new MemoryStream())
    {
        zipStream.CopyTo(resultStream);
        return resultStream.ToArray();
    }
}

如何修剪流并将其起始点设为1F8B。

1 个答案:

答案 0 :(得分:2)

搜索searchstring并剪切字符串,使其以searchstring开头 - 您可以轻松地执行此操作:

string hexstr = http.Body.ToString();
string search = "1f8b";
if (hexstr.Contains(search))
{
   int pos = hexstr.IndexOf(search);
   hexstr = hexstr.Substring(pos, hexstr.Length - pos);
   // do something additional with hexstr...
}