I have this code:
List<string> lineList = new List<string>();
in j = 0;
Dictionary<string, int> dictionary = new Dictionary<string, int>();
lineList = theFinalList.Select( line =>
{
if (line.PartDescription != "")
return line.PartDescription + " " + line.PartNumber + " " + line.TapeWidth + "\n";
else
return "N/A " + line.PartNumber + " " + line.TapeWidth + "\n";
})
.Where(x => !(x.Contains("FID") || x.Contains("EXCLUDE")))
.ToList();
foreach (string word in lineList)
{
if (dictionary.ContainsKey(word))
dictionary[word]++;
else
dictionary[word] = 1;
}
var ordered = from k in dictionary.Keys
orderby dictionary[k] descending
select k;
foreach (string key in ordered)
{
var splitKey = key.Split(' ');
if (!splitKey[2].Contains("8"))
{
sw.WriteLine(string.Format("( {0} 0 1 1 0 0 0 0 \"\" \"\" \"\" 0 0 0 0 0 0 )", j);
j++;
}
sw.WriteLine(string.Format("( {0} 0 1 1 0 0 0 0 \"{1}\" \"{2}\" \"\" {3} 0 0 0 0 0 )",
j, splitKey[0], splitKey[1], dictionary[key]));
j++;
}
An example of this output looks like this (assuming all of the line.TapeWidth‘s do NOT contain “8”):
( 1 0 1 1 0 0 0 0 "2125R_1.0" "136380" "" 18 0 0 0 0 0 )
( 2 0 1 1 0 0 0 0 "2125R_1.0" "128587" "" 41 0 0 0 0 0 )
( 3 0 1 1 0 0 0 0 "2125R_1.0" "138409" "" 11 0 0 0 0 0 )
( 4 0 1 1 0 0 0 0 "2125R_1.0" "110984" "" 8 0 0 0 0 0 )
( 5 0 1 1 0 0 0 0 "3216R_1.3" "114441" "" 6 0 0 0 0 0 )
HOWEVER
I would like to change it so if the !line.TapeWidth.Contains("8") then I would like to output an extra line.. Let’s say that the line that contained "138409" and "114441" both had a TapeWidth that was not equal to 8. so the NEW output would look like this:
( 1 0 1 1 0 0 0 0 "2125R_1.0" "136380" "" 18 0 0 0 0 0 )
( 2 0 1 1 0 0 0 0 "2125R_1.0" "128587" "" 41 0 0 0 0 0 )
( 3 0 1 1 0 0 0 0 "" "" "" 0 0 0 0 0 )
( 4 0 1 1 0 0 0 0 "2125R_1.0" "138409" "" 11 0 0 0 0 0 )
( 5 0 1 1 0 0 0 0 "2125R_1.0" "110984" "" 8 0 0 0 0 0 )
( 6 0 1 1 0 0 0 0 "" "" "" 0 0 0 0 0 )
( 7 0 1 1 0 0 0 0 "3216R_1.3" "114441" "" 6 0 0 0 0 0 )
So
I am trying to insert that “blank” line BEFORE the other line is printed off…
Does anyone know how I can do this?
This seems like an easy way to do it, just check for the condition before you print the line.