This one also:
http://www.motobit.com/tip
Main Topics
Browse All TopicsHello,
Please suggest any solution how to replace string in large files(~20mb) using .NET?
Regards,
Tomas
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This one also:
http://www.motobit.com/tip
This is code for c++ not for .NET http://www.codeproject.com
This is also not native NET code, it use VB scripting.
<<This one also:
http://www.motobit.com/tip
Well, a 20MB file is not too large to handle in memory, unless you do it frequently:
File.WriteAllText(fileName
If what you replace doesn't contain line breaks, you can use a temporary file and replace one line at a time:
string tempName = fileName + ".temp";
File.Move(fileName, tempName);
using (StreamReader reader = New StreamReader(tempName)) {
using (StreamWriter writer = new StreamWriter(fileName)) {
string line;
while ((line = reader.ReadLine()) != null) {
writer.WriteLine(line.Repl
}
}
}
file.Delete(tempName);
I want to clarify my requirements, I need 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.
You can't find it because it is not there. There is no bulit-in way to scan a file for a particular binary sequence. That said, scanning the file manually, byte by byte, is not such a hard thing to do. You can prefetch chunks of it and perform the byte scan in memory on each chunk, which should be faster.
A word of caution: when replacing the string, you must make sure that the new string is of the same length, otherwise may mangle the file. If the string with which you are replacing is of a different size, then I suggest opening a temporary output file and write to it everything you read from the original file until the string you found; then write the replacement string, followed by the rest of the original file. When done, rename the temporary file to replace the original.
-dZ.
Business Accounts
Answer for Membership
by: isaackhaziPosted on 2009-02-04 at 00:01:09ID: 23545759
http://www.codeproject.com /KB/files/ scanr.aspx
try this
Code included