Im having problem getting creating the last file.
I have a tab delimited text file that looks like this.
KABEL Provkanna for Windchill_NWF-TSNM =2212.U001+++-X2 PXC.2400016 =2271.U004+++-X1 Test_Created_in_WT =2212-W123 RXF 4x25 0000000440 Cable RXF 4x25
PART 01 1 1
PART 02 2 2
PART 03 3 3
PART 04 4 4
PART SH GND GND
KABEL Provkanna for Windchill_NWF-TSNM =2212.U001+++-X2 PXC.2400016 =2271.U004+++-X1 Test_Created_in_WT =2212-W124 RXF 4x35 0000000456 Cable RXF 4x35
PART 01 1 5 5
PART 02 1 6 6
PART 03 1 7 7
PART 04 1 8 8
PART SH 1 GND GND
KABEL Provkanna for Windchill_NWF-TSNM =2212.U001+++-X2 PXC.2400016 =2271.U004+++-X1 Test_Created_in_WT =2212-W125 RXF 4x35 0000000456 Cable RXF 4x35
PART 01 1 9 9
PART 02 1 10 10
PART 03 1 11 11
PART 04 1 12 12
PART SH 1 GND GND
Basically it is a row starting with the Word KABEL followed by a number of tab delimited columns. This line is then followed by some lines starting with the word PART. The number of lines starting with PART can differ.
Now I want this file to be broken down into several files.
Every parsed file shall have a name containing information from a certain column of the line starting with KABEL. In that file every line following starting with PART shall be added.
Then when a line staring with KABEL shows up again a new file will be created and the PART-lines shall be added to that file... and so on ... and so on.
I have tried a lot back and forth and finaly found a way to create the first two files correctly... but... the last file wont be created.
My script reads and finds and displays the correct column of what is supposed to be the unique part of the last parsed outputfile but I dont see any file being output.
Any takers? I will very much appriciate your help since Im stuck...
{
string line ="";
string ColumnValue ="";
string Starttext = "PART";
string Kabeltext = "KABEL";
int column = 16;
string FilenameWithoutCabelNumber = @"C:\Users\tsnm2171\Desktop\processed\LABB\OUTPUT - Provkanna for Windchill_NWF-TSNM_2212_CABLE_CONNECTION";
string ExportfileIncCablenumber ="";
string filecontent ="";
using (System.IO.StreamReader reader = new System.IO.StreamReader(@"C:\Users\tsnm2171\Desktop\processed\LABB\Provkanna for Windchill_NWF-TSNM_2212_CABLE_CONNECTION.txt"))
{
line = reader.ReadLine();
//Set columninnehåll till filnamn (String ColumnValue)
string [] words = line.Split();
ColumnValue = words[column];
MessageBox.Show (ColumnValue);
while (line != null)
{
line = reader.ReadLine();
if (line.StartsWith(Kabeltext)) // if line starts with KABEL
{
ExportfileIncCablenumber = (FilenameWithoutCabelNumber + "-" + ColumnValue + ".txt");
System.IO.File.WriteAllText(ExportfileIncCablenumber, filecontent);
filecontent = string.Empty;
string [] words2 = line.Split();
ColumnValue = words2[column];
MessageBox.Show("Ny fil " + ColumnValue);
}
else if (line.StartsWith(Starttext)) // if line starts with PART
{
filecontent += ((line)+"\n"); //writes the active line
}
}
ExportfileIncCablenumber = (FilenameWithoutCabelNumber + "-" + ColumnValue + ".txt");
System.IO.File.WriteAllText(ExportfileIncCablenumber, filecontent); filecontent = "";
}
}
Thanks in advance
Tomas