Replace string in binary file

  • Thread starter Thread starter Tomas
  • Start date Start date
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
 
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);}
 
Back
Top