D
d4
I have a vbscript (below) I want to rewrite in C# but I cannot get it
to work (unless there is a better way to do it).
The script will combine 2 lines if the (next) line contains a "+",
otherwise just write the line.
#### vbscript:
Do While Not InputFile.AtEndofStream
Line = InputFile.ReadLine
If Len(Line) = 0 Then
Exit Do ' Exit at last line because it is empty
End If
If Mid(Line, 26, 1) = "+" Then
out = out & Mid(Line, 27)
Else
If Len(Out) Then
OutputFile.WriteLine(out)
End If
out = Left(Line, 15) & ";;" & RTrim(Mid(Line, 32, 8)) &
";;" & Mid(Line, 66)
End If
Loop
OutputFile.WriteLine(out)
OutputFile.Close()
InputFile.Close()
#### Below is the C# version I cannot get to work...
private static void CreateText()
{
string inFile = @"c:\Text.txt";
string outFile = @"C:\OutText.txt";
StreamReader sr = new StreamReader(inFile);
StreamWriter sw = new StreamWriter(File.Create(outFile));
while (!(sr.EndOfStream))
{
string Line = sr.ReadLine();
if (Line.Length == 0) {
goto exitDoLoopStatement0;
}
if (Line.Substring(26, 1) == "+")
{
string outL = outL + Line.Substring(27);
} else
{
if (Line.Length > 0) {
sw.WriteLine(outL);
}
outL = Line.Substring(0, 15) + ";" + Line.Substring(31,
8).TrimEnd() + ";" + Line.Substring(65);
}
}
exitDoLoopStatement0: ;
sw.WriteLine(outL);
sr.Close();
sw.Close();
}
### Text file: Text.txt
06.299 22:06:34 HBR10224W DUID=SERVER29: ABORTED BY CLIENT,
FILE=C:\Program Files\Websense Reporter\LogServer\Cache\LogServer.state
06.299 22:06:36 HBR10224W DUID=SERVER29: ABORTED BY CLIENT,
FILE=D:\Program Files\ISS\RealSecure SiteProtector\Site
Database\Data\Re
06.299 22:06:36 HBR10224W+alSecureDB.mdf
06.299 22:06:36 HBR10224W DUID=SERVER29: ABORTED BY CLIENT,
FILE=D:\Program Files\ISS\RealSecure SiteProtector\Site
Database\Data\Re
06.299 22:06:36 HBR10224W+alSecureDBLog.ldf
06.299 22:06:52 HBR10224W DUID=SERVER1 : ABORTED BY CLIENT,
FILE=C:\STATIC\straudit.log
06.299 22:06:52 HBR10224W DUID=SERVER1 : ABORTED BY CLIENT,
FILE=C:\STATIC\strerror.log
06.299 22:06:52 HBR10224W DUID=SERVER1 : ABORTED BY CLIENT,
FILE=C:\STATIC\trace
06.299 22:09:13 HBR10224W DUID=SERVER8 : ABORTED BY CLIENT,
FILE=D:\perfdata_DB\perfdata_Data.MDF
Any help or suggestions would be greatly appreciated.
to work (unless there is a better way to do it).
The script will combine 2 lines if the (next) line contains a "+",
otherwise just write the line.
#### vbscript:
Do While Not InputFile.AtEndofStream
Line = InputFile.ReadLine
If Len(Line) = 0 Then
Exit Do ' Exit at last line because it is empty
End If
If Mid(Line, 26, 1) = "+" Then
out = out & Mid(Line, 27)
Else
If Len(Out) Then
OutputFile.WriteLine(out)
End If
out = Left(Line, 15) & ";;" & RTrim(Mid(Line, 32, 8)) &
";;" & Mid(Line, 66)
End If
Loop
OutputFile.WriteLine(out)
OutputFile.Close()
InputFile.Close()
#### Below is the C# version I cannot get to work...
private static void CreateText()
{
string inFile = @"c:\Text.txt";
string outFile = @"C:\OutText.txt";
StreamReader sr = new StreamReader(inFile);
StreamWriter sw = new StreamWriter(File.Create(outFile));
while (!(sr.EndOfStream))
{
string Line = sr.ReadLine();
if (Line.Length == 0) {
goto exitDoLoopStatement0;
}
if (Line.Substring(26, 1) == "+")
{
string outL = outL + Line.Substring(27);
} else
{
if (Line.Length > 0) {
sw.WriteLine(outL);
}
outL = Line.Substring(0, 15) + ";" + Line.Substring(31,
8).TrimEnd() + ";" + Line.Substring(65);
}
}
exitDoLoopStatement0: ;
sw.WriteLine(outL);
sr.Close();
sw.Close();
}
### Text file: Text.txt
06.299 22:06:34 HBR10224W DUID=SERVER29: ABORTED BY CLIENT,
FILE=C:\Program Files\Websense Reporter\LogServer\Cache\LogServer.state
06.299 22:06:36 HBR10224W DUID=SERVER29: ABORTED BY CLIENT,
FILE=D:\Program Files\ISS\RealSecure SiteProtector\Site
Database\Data\Re
06.299 22:06:36 HBR10224W+alSecureDB.mdf
06.299 22:06:36 HBR10224W DUID=SERVER29: ABORTED BY CLIENT,
FILE=D:\Program Files\ISS\RealSecure SiteProtector\Site
Database\Data\Re
06.299 22:06:36 HBR10224W+alSecureDBLog.ldf
06.299 22:06:52 HBR10224W DUID=SERVER1 : ABORTED BY CLIENT,
FILE=C:\STATIC\straudit.log
06.299 22:06:52 HBR10224W DUID=SERVER1 : ABORTED BY CLIENT,
FILE=C:\STATIC\strerror.log
06.299 22:06:52 HBR10224W DUID=SERVER1 : ABORTED BY CLIENT,
FILE=C:\STATIC\trace
06.299 22:09:13 HBR10224W DUID=SERVER8 : ABORTED BY CLIENT,
FILE=D:\perfdata_DB\perfdata_Data.MDF
Any help or suggestions would be greatly appreciated.