I have a program in 2005 that is reading a text file removing text and then
writing it back out again. It removes lines that start with PRINT.
This program has worked fine for months. Now all of a sudden, it is reading
a straight text file and adding a null after each character it reads in.
Why is that?
The original file doesn't have nulls in them. The code is:
*************** *************** **************
using System;
using System.IO;
using System.Collecti ons.Generic;
using System.Text;
namespace DeletePrintStat ements
{
class Program
{
static void Main(string[] args)
{
string lineDisplay;
string oldLineDisplay;
FileStream fs = null;
StreamReader sr = null;
fs = new FileStream(@"D: \Database
Scripts\Current Schema101408.sq l", FileMode.Open, System.IO.FileA ccess.Read);
sr = new StreamReader(fs );
StreamWriter sw = null;
sw = File.CreateText (@"D:\Databas e
Scripts\Current SchemaNoPrint10 1408.sql");
string stemp = null;
sw.WriteLine("s et nocount on");
while (sr.Peek() >= 0)
{
lineDisplay = sr.ReadLine();
if (lineDisplay.Le ngth >= 4) stemp =
lineDisplay.Sub string(0, 4);
if ((lineDisplay.L ength < 5) || (lineDisplay.Su bstring(0, 5)
!= "PRINT"))
sw.WriteLine(li neDisplay);
else
{
// Since last line was not a Print statement make sure
next line is = "GO" and if so ignore it
if (sr.Peek() >= 0)
{
oldLineDisplay = lineDisplay;
lineDisplay = sr.ReadLine();
if ((lineDisplay.L ength < 2) ||
(lineDisplay.Su bstring(0, 2) != "GO"))
{
sw.WriteLine(ol dLineDisplay); // Should only be
the "Update Succeeded" line
// or a print
statement inside of a SP
sw.WriteLine(li neDisplay);
}
}
}
Console.WriteLi ne(lineDisplay) ;
}
fs.Close();
sr.Close();
sw.Close();
Console.ReadLin e();
}
}
}
*************** *************** **************
I have tried closing an reopening the program but it keeps doing the same
thing.
Thanks,
Tom
writing it back out again. It removes lines that start with PRINT.
This program has worked fine for months. Now all of a sudden, it is reading
a straight text file and adding a null after each character it reads in.
Why is that?
The original file doesn't have nulls in them. The code is:
*************** *************** **************
using System;
using System.IO;
using System.Collecti ons.Generic;
using System.Text;
namespace DeletePrintStat ements
{
class Program
{
static void Main(string[] args)
{
string lineDisplay;
string oldLineDisplay;
FileStream fs = null;
StreamReader sr = null;
fs = new FileStream(@"D: \Database
Scripts\Current Schema101408.sq l", FileMode.Open, System.IO.FileA ccess.Read);
sr = new StreamReader(fs );
StreamWriter sw = null;
sw = File.CreateText (@"D:\Databas e
Scripts\Current SchemaNoPrint10 1408.sql");
string stemp = null;
sw.WriteLine("s et nocount on");
while (sr.Peek() >= 0)
{
lineDisplay = sr.ReadLine();
if (lineDisplay.Le ngth >= 4) stemp =
lineDisplay.Sub string(0, 4);
if ((lineDisplay.L ength < 5) || (lineDisplay.Su bstring(0, 5)
!= "PRINT"))
sw.WriteLine(li neDisplay);
else
{
// Since last line was not a Print statement make sure
next line is = "GO" and if so ignore it
if (sr.Peek() >= 0)
{
oldLineDisplay = lineDisplay;
lineDisplay = sr.ReadLine();
if ((lineDisplay.L ength < 2) ||
(lineDisplay.Su bstring(0, 2) != "GO"))
{
sw.WriteLine(ol dLineDisplay); // Should only be
the "Update Succeeded" line
// or a print
statement inside of a SP
sw.WriteLine(li neDisplay);
}
}
}
Console.WriteLi ne(lineDisplay) ;
}
fs.Close();
sr.Close();
sw.Close();
Console.ReadLin e();
}
}
}
*************** *************** **************
I have tried closing an reopening the program but it keeps doing the same
thing.
Thanks,
Tom
Comment