C#怎么在指定的1A2B3C后开始读取文件,初学者,不知道用啥实现,知道数组里能找Contains内容,但这个是BYTE,求程序
byte[] data = File.ReadAllBytes("frame_0_right.dat");
int i = 0;
for (i = 0; i < data.Count() - 3; i++)
{
if (data[i] == 0x1a && data[i + 1] == 0x2b && data[i + 2] == 0x3c) break;
}
// i + 3为你需要的位置
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace DECODE
{
class Program
{
static void Main(string[] args)
{
string path = @"frame_0_right.dat";
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Byte data = br.ReadByte();
string str = System.Text.Encoding.Default.GetString(byte[data]);
Console.Write(data.ToString("X2"));
Console.Read();
}
}
}
比如这个,为什么转换不成功
byte[] data = File.ReadAllBytes("frame_0_right.dat");
int i = 0;
for (i = 0; i < data.Count() - 3; i++)
{
if (data[i] == 0x1a && data[i + 1] == 0x2b && data[i + 2] == 0x3c) break;
}