avgcoder
avgcoder

Reputation: 392

Byte array to string in visual basic

I've done some research on changing bytes to strings but I am not sure where I have to begin with the specific file I have.

I have a file called Options.mco and when I open it in notepad++ or notepad it's all just gibberish.

http://puu.sh/3lHJD.png

http://puu.sh/3lHKm.png

So I want to turn these bytes into strings so that I can then edit them in my program depending on what option the user chooses and then change them back into byte form and save it in the file keeping the same file structure.

From my research I found out how to convert bytes into string and string into bytes but I am not sure where to start with this because of it's layout and how I should import or view it after the bytes have been converted.

Upvotes: 0

Views: 748

Answers (2)

tinstaafl
tinstaafl

Reputation: 6948

Sussing out the format of the file? How do I do this?

A hex editor will help. Knowing the software that generated the file will help to identify what type of information is in the file.

Upvotes: 0

DougM
DougM

Reputation: 2888

You need to know the layout of that Options.mco file. It sounds like a binary file written to disk from memory, which means that you have all of the issues with reading a flat text file, plus character encoding, plus not having any good way to tell the difference between "this bit is part of a string" and "that bit is a boolean value."

If you have any control at all over the generation of the file, consider switching to XML or JSON (or, heck, INI or just plain text) to store the options.

Otherwise, you will need to determine exactly how the Options.mco file is laid out internally, parse out the strings viable to change, change the strings, put them back, convert your strings back to binary, write back to the file... and hope that you didn't flip a bit somewhere that makes the entire thing corrupt.

Upvotes: 1

Related Questions