从字符串数组中复制字节,从匹配的字符串的位置开始。 [英] Copy bytes from array of bytes , from the position of string matched.

查看:99
本文介绍了从字符串数组中复制字节,从匹配的字符串的位置开始。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家都在这里我正在读缓冲区,我会通过增加最后3位来搜索字符串几次,我想从缓冲区中每个字符串搜索复制字节,从搜索字符串的起始位置到大约554字节,并将554个字节复制到另一个缓冲区,将其视为数据包。







我尝试过:



Hi all here I am reading a buffer, and I'll search string several times by increasing last 3 digits, I want to copy bytes per each string search from buffer , from the starting position of searched string to till about 554 bytes, and copy the 554 bytes to another buffer considering it as a packet.

,

What I have tried:

FileStream fssource1 = new FileStream(file1, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

           byte[] source1 = new byte[fssource1.Length];
           numBytesToRead = (int)fssource1.Length;
           numBytesRead = 0;
           while (numBytesToRead > 0)
           {

               int n = fssource1.Read(source1, numBytesRead, numBytesToRead);

               // Break when the end of the file is reached.
               if (n == 0)
                   break;

               numBytesRead += n;
               numBytesToRead -= n;
           }
           numBytesToRead = source1.Length;
           fun.extract(ref source1);





和匹配的字符串如下,我不知道进一步的行动,





and matching string as follows and I don't know further action,

>public void extract(ref byte[] buffer)
       {



           for (int i = 108; i <= nNoofPackets; i++)
           {
               string search = "MINDFLOWfP"+i.ToString().PadLeft(3,Convert.ToChar("0"));

               var index = Array.IndexOf(buffer, search);
               if (index!=-1)

{

推荐答案

如果您有索引,那么只需复制该部分你想要的数组: Array.Copy Method(Array,Int32,Array, Int32,Int32)(系统) [ ^ ]就是这样做的。
If you've got the index, then just copy the section of the array you want: Array.Copy Method (Array, Int32, Array, Int32, Int32) (System)[^] is there to do exactly that.


这篇关于从字符串数组中复制字节,从匹配的字符串的位置开始。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆