0
You're welcome.
0
string cline;
string iline="";
try
{
using (StreamReader isr = new StreamReader(ifile))
{
iline = isr.ReadToEnd();
using (StreamReader csr = new StreamReader(cfile))
{
using (StreamWriter sw = new StreamWriter(ofile))
{
while ((cline = csr.ReadLine()) != null)
{
Regex testExp = new Regex( cline );
string replaceString = "!REPLACEMENT!";
if (iline != null)
{
iline = testExp.Replace( iline, replaceString );
Console.WriteLine(iline);
// }
}// end while iline
} // end while cline
sw.Write(iline);
} // end streamwriter
} // end using StreamReader csr
} // end using StreamReader isr
} // End Try block
Thanks to Lee for the solution.
0
Lee, thank you for replying.
To answer your questions:
1. The config file is just a static text file. It does not change. It just has a few lines, all of which contain some basic expressions like "A0-1234", "X2-765823" etc.
I'm sorry but I did not really understand what you recommended in your first point. Could you please clarify ?
2. Even if I read the file into a string or read it to end, how will I be able to compare the entire input text file repeatedly with the search expressions stored in the string ?
Thanks.
0
Firstly: Does your config file change? if not use App.config and the System.Configuration library.
you can retrieve the settings with "ConfigurationSettings.AppSettings[""].ToString();".
for a count of the settings use: ConfigurationSettings.AppSettings.Count;
Secondly: Read the file into a string and add "\n" after each line is loaded or use read to end.
string sInFile = isr.ReadToEnd();