---
title: "Binary Pattern Search"  
description: "Binary Pattern Search"  
author: "Anonymous User"  
published: 2011-04-23  
updated: 2011-04-23  
canonical: https://www.mindstick.com/forum/227/binary-pattern-search  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Binary Pattern Search

Hi Everyone,\
\
I wanna [search](https://www.mindstick.com/articles/65368/best-smo-services-company-in-hyderabad-improve-search-rankings) a [binary file](https://www.mindstick.com/forum/161626/how-do-you-serialize-and-save-an-object-to-a-binary-file) for this [pattern](https://www.mindstick.com/forum/2314/what-is-the-mvp-and-mvc-pattern) '00 00 00 08 00' then to read 8 bytes after it into a variable.\
\
Please help!

## Replies

### Reply by Uttam Misra

```
namespace XYZ{    public partial class Form1 : Form {        StringBuilder bldr = new StringBuilder();        byte[] readFromFile;        Regex hexPattern = new Regex("0000000800(?<binaryText>.{16})");        MatchCollection matchBinary;        FileStream bStream = new FileStream("C:\\XYZ.bin", FileMode.Open, FileAccess.Read);        BinaryReader fruity;        public Form1() {            InitializeComponent();            using (fruity = new BinaryReader(bStream)) {                readFromFile = fruity.ReadBytes(31);            }            // create a hex-dump formatted string             // from the binary file input data             foreach (byte thisbyte in readFromFile) {                bldr.Append(thisbyte.ToString("x2"));            }            // then search the hex-dump-format string for the            // pattern he seeks. 'Capture' the eight bytes which            // follow the pattern.            matchBinary = hexPattern.Matches(bldr.ToString());            // No recovery required ... just index the data bytes            // in 'readFromFile' using the index supplied by Regex.        }// end constructor    }// end class Form1}// end Namespace ‘XYZ’
```

\


---

Original Source: https://www.mindstick.com/forum/227/binary-pattern-search

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
