Uday321

Hi All,

I have a text file where ever the string "xxx" appear in the text file i have to replace it with "yyy"(without creating the second text file) any help will be greatly appreciated...


Thanks,
Uday..


Re: .NET Base Class Library How to modify Text file in c#

Manju Sandhu

Hi,

Just use this code.

StreamReader reader = new StreamReader(File.OpenRead("C:\file.txt"));

string fileContent = reader.ReadToEnd();

reader.Close();

fileContent = fileContent.Replace("xxx","yyy");

StreamWriter writer =new StreamWriter(File.OpenWrite("C:\file.txt"));

writer.Write(fileContent);

writer.Close();

Regards,

Manju Sandhu





Re: .NET Base Class Library How to modify Text file in c#

Uday321

Thanks. for u r reply