Replace string in binary file

T

Tomas

Hello,

Maybe someone could point me how to replace string in binary file? The
string is the same lenght but located in diferent places depend on file
and files are large, about 20mb. So I can't use function which load a whole
file to memory. I have browsed .Net functions related to file manipulation
but didn't found any usefull.

regards,
Tomas
 
T

Tomas

Thank you Peter for your answer. The problem is that I don't find method
which will find offset of string.
Look at code below


string dataString = "Something to put in the file";int pos = How to find
string offset which I would like to replace here?; byte[] data =
Encoding.ASCII.GetBytes(dataString);using (FileStream s = new
FileStream(fileName, FileMode.Open, FileAccess.ReadWrite)) { s.Seek(pos,
SeekOrigin.Begin); s.Write(data, 0, data.Length);}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top