Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:33:03+00:00 2026-06-07T03:33:03+00:00

I am working on a project where I read data from a file and

  • 0

I am working on a project where I read data from a file and I need to manipulate some of this data.

The data is binary with some ASCII encoded text in it.
The data is also saved Big Endian if that matters.

What I would like to accomplish is to find a pattern with in this data and manipulate parts of that pattern.

Example: (09 49 6E 76 65 6E 74 6F 72 79 0A 00 00 00 02 01 00)

This represents the number 9 for how many letters are in Inventory, followed by ASCII "Inventory" without quotes. "0A" Marks the end of that ASCII text, followed with 00 00 00 02 to mark the size of our inventory "2". "01 00" Marks the end of The entire inventory region.

Example2: (04 53 6C 6F 74 00 02 00)

This represents the number 4 for how many letters are in Slot, followed by ASCII "Slot" without quotes. "00" is a space between ASCII text and Slot number "02", followed by end of region "00".

I need to locate these patterns and several others within the file.
I then need to modify parts of the pattern and write to disk.

ExampleModify: (04 53 6C 6F 74 00 02 00) "From above" to (04 53 6C 6F 74 00 07 00) changing "slot number ’02’ to ’07’.

Another caveat is that while I have several patterns that I need to search in the file of varying size, length, and data contained, is that there can be multiple sections of these patterns containing different data that needs to be modified separately as a whole.

To clarify: (Inventory, Slot, id, Count) – is to be treated as information for one person.

There can be multiple copies of (Inventory, Slot, id, Count) for each person that is recorded.

I would like to display this information to the user, and give them the option to modify each of the elements in the group.

I am not a good programmer and want to learn, if you have examples I appreciate that, if you have advice please give it. If you can dumb it down that is even better, thanks.
I have a work-in-progress going now, but I am stuck now. If you want to see what I have please let me know.

Summary of what I have: Read file into byte[] then display the whole array to console. That’s about it. with a little bit of formatting and some debug info for locating that chunk I read into the array.

Here is a link to my code on pastebin. LINK

I realize that I do not get all occurrences of (Inventory, Slot, id, Count) I need to fix that as well.

EDIT: Example (09 49 6E 76 65 6E 74 6F 72 79 0A 00 00 00 02 01 00) this is a fixed length chunk of binary data within the file I’m reading. As stated 09 represents the length of the string. what follows the string is (0A 00 00 00 02 01 00) the important part of that is (02)
this is because that is the only byte(s) that change in that slice of binary data. "02" represents "2" meaning there are 2 instances of (Slot, id, Count) for that particular persons record.

(File)
    (09 Inventory 0A 00 00 00 02 01 00) // Start of person 1's record with 2 instances.
        (Slot)
        (id)
        (Count)
        (Slot)
        (id)
        (Count)
    (Rotation)  // End of person 1's record

    (09 Inventory 0A 00 00 00 04 01 00) // Start of person 2's record with 4 instances.
        (Slot)
        (id)
        (Count)
        (Slot)
        (id)
        (Count)
        (Slot)
        (id)
        (Count)
        (Slot)
        (id)
        (Count)
    (Rotation)  // End of person 2's record
(File End)

The idea is that I want to edit the "id" or increase the number of slots by adding to the inventory and add in more instances of (Slot, id, Count).

"id" – contains item id

"Slot" – contains inventory slot number

"Count" – contains how many of item is in that slot.
EDIT Note: Please let me know if I am not being clear, thank you again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:33:05+00:00Added an answer on June 7, 2026 at 3:33 am

    You said you’re not a good programmer. I’ll make some basic suggestions then.

    First, for any problem, break it down. Try to break it up into simpler sub-problems that you can solve, or think will be easier to solve. You said you wanted to check for patterns in a file, and then maybe modify some of the data and write it back out. As a first step, I’d say these are the major sub-problems you need to solve in order to get to a complete solution.

    • read the file
    • search for patterns in the binary data
    • make the modifications
    • write the modified data out.

    You focused mostly on “search for patterns” part, so I will focus further comments on that. All those other pieces can also be tricky, but you can either solve them yourself or look for hints on stackoverflow or in other places for how other people solved them.

    ok, now, regarding “search for patterns” . In my reading of your description,

    It seems to me the first byte in your byte array is the text length. In C# code, a data array that exhibits your pattern could be declared explicitly like this:

    byte[] data = new byte[] { 9, 0x49, 0x6E, 0x76, 0x65, 0x6E, 0x74,
                   0x6F, 0x72, 0x79, 0x0A, 0, 0, 0, 2, 1, 0 } ;
    

    of course, you won’t be declaring the array explicitly. You’ll be creating or filling array via the file-read operation. The file-read is still an open problem at this point, but that’s ok – you can solve it separately. And, the effect is the same – when you have successfully read the file, you will have a byte array that looks like the array that is explicitly declared above.

    ok, now how do you manipulate that data? The first byte is the length of string data. The next N bytes are the string data. Then you have some other stuff.

    you didn’t describe exactly what “modifications” you want to make, but with the information you have provided, it should be easy to walk through the data.

    If you want to get a “slice” of the data in an array, you can do this .

    int length = (int) data[0];
    byte[] s = new byte[length];
    Array.Copy(data, 0, s, 0, length);
    // now, s contains N bytes, representing the string
    

    The next thing you might want to do is get an actual string out of those bytes you’ve sliced out. To do that, use the Encoding class:

    String word = System.Text.Encoding.UTF8.GetString(s);
    

    I don’t understand the pattern for the data that follows the string data. In some cases it’s a 00, in some cases it’s 0A.

    But maybe you know the pattern. Follow along the same way and you can walk through all the data for one “record”. When you get to the end of the record, then start again and process the next one. The key to getting to the next “Record” is knowing how large a slice of data to take out of the data you have read from the file.


    This brings us back to the “reading the file” sub-problem. One way to get the right amount of data from the file is to read only the first byte, then read N bytes further in the file. (See System.IO.Stream.Read).

    byte[] size = new byte[1];
    var fileStream = File.OpenRead(path);
    int offset = 0;
    int n;
    n = fileStream.Read(size, offset, 1);
    // size[0] now contains the byte of data indicating the number of bytes to follow
    

    At this point you can read the next N bytes:

    int length = (int)size[0];
    byte[] stringData = new byte[length];
    n = fileStream.Read(stringData, offset, length);
    

    Now you can get the string.

    String word = System.Text.Encoding.UTF8.GetString(stringData);
    

    …and so on. Read all the trailing bytes. At that point the cursor that is implicitly held by the fileStream points to the next record in the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a project I'm working on, I need to read from a CSV file,
I am working on a project where I need to read data from a
I am working on this project where I need to read in a lot
I am lost on this MVC project I am working on. I also read
I'm working on a project and I need to read a CSV file and
i have been working on this text extraction project of various file extensions, but
I was working on a project and I need to read a row in
I'm trying to read data from 1.txt in my iphone project's resources folder using
I'm currently working on a python project, that requires file transmission from a client
While working a project tonight, I ended up using one .js resource file for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.