T
tshad
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.Collections.Generic;
using System.Text;
namespace DeletePrintStatements
{
class Program
{
static void Main(string[] args)
{
string lineDisplay;
string oldLineDisplay;
FileStream fs = null;
StreamReader sr = null;
fs = new FileStream(@"D:\Database
Scripts\CurrentSchema101408.sql", FileMode.Open, System.IO.FileAccess.Read);
sr = new StreamReader(fs);
StreamWriter sw = null;
sw = File.CreateText(@"D:\Database
Scripts\CurrentSchemaNoPrint101408.sql");
string stemp = null;
sw.WriteLine("set nocount on");
while (sr.Peek() >= 0)
{
lineDisplay = sr.ReadLine();
if (lineDisplay.Length >= 4) stemp =
lineDisplay.Substring(0, 4);
if ((lineDisplay.Length < 5) || (lineDisplay.Substring(0, 5)
!= "PRINT"))
sw.WriteLine(lineDisplay);
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.Length < 2) ||
(lineDisplay.Substring(0, 2) != "GO"))
{
sw.WriteLine(oldLineDisplay); // Should only be
the "Update Succeeded" line
// or a print
statement inside of a SP
sw.WriteLine(lineDisplay);
}
}
}
Console.WriteLine(lineDisplay);
}
fs.Close();
sr.Close();
sw.Close();
Console.ReadLine();
}
}
}
********************************************
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.Collections.Generic;
using System.Text;
namespace DeletePrintStatements
{
class Program
{
static void Main(string[] args)
{
string lineDisplay;
string oldLineDisplay;
FileStream fs = null;
StreamReader sr = null;
fs = new FileStream(@"D:\Database
Scripts\CurrentSchema101408.sql", FileMode.Open, System.IO.FileAccess.Read);
sr = new StreamReader(fs);
StreamWriter sw = null;
sw = File.CreateText(@"D:\Database
Scripts\CurrentSchemaNoPrint101408.sql");
string stemp = null;
sw.WriteLine("set nocount on");
while (sr.Peek() >= 0)
{
lineDisplay = sr.ReadLine();
if (lineDisplay.Length >= 4) stemp =
lineDisplay.Substring(0, 4);
if ((lineDisplay.Length < 5) || (lineDisplay.Substring(0, 5)
!= "PRINT"))
sw.WriteLine(lineDisplay);
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.Length < 2) ||
(lineDisplay.Substring(0, 2) != "GO"))
{
sw.WriteLine(oldLineDisplay); // Should only be
the "Update Succeeded" line
// or a print
statement inside of a SP
sw.WriteLine(lineDisplay);
}
}
}
Console.WriteLine(lineDisplay);
}
fs.Close();
sr.Close();
sw.Close();
Console.ReadLine();
}
}
}
********************************************
I have tried closing an reopening the program but it keeps doing the same
thing.
Thanks,
Tom