There isn't much you can optimize about the I/O, most of the optimization should be on the string comparison to determine if the string should be replaced or not, basically you should do this
protected void ReplaceFile(string FilePath, string NewFilePath)
{
using (StreamReader vReader = new StreamReader(FilePath))
{
using (StreamWriter vWriter = new StreamWriter(NewFilePath))
{
int vLineNumber = 0;
while (!vReader.EndOfStream)
{
string vLine = vReader.ReadLine();
vWriter.WriteLine(ReplaceLine(vLine, vLineNumber++));
}
}
}
}
protected string ReplaceLine(string Line, int LineNumber )
{
//Do your string replacement and
//return either the original string or the modified one
return Line;
}
What is your criteria to find and replace a string?