First post ever so please forgive if I am out of line.
StreamWriter noteswriter = new StreamWriter(directoryPath + "\\" + "Notes.CSV");
var NotesQuery =
from w in
(from line in BillSummaryQuery1
let linerecord2 = line.Split(',').ToList()
where linerecord2[0] == "RB" && linerecord2[1] == "MICA" && linerecord2[6].Trim() == "1" && linerecord2[7].Trim() == "H" && linerecord2[9].Trim() == "D" && Regex.IsMatch(linerecord2[10].Substring(4, 1), @"^[a-zA-Z0-9]*$") && linerecord2[10].Substring(2, 1) == " "
select string.Concat(linerecord2[2], ",", linerecord2[3], ",", linerecord2[10].Trim())
)
let lineorder3 = w.Split(',').ToList()
select new
{
colA = lineorder3[0],
colB = lineorder3[1],
colC = lineorder3[2]
};
var NotesQuery1 =
from w in NotesQuery
group w by new { w.colA, w.colB, w.colC } into g
select new
{
colA = g.Key.colA,
colB = g.Key.colB,
colC = g.Key.colC
};
foreach (var item in NotesQuery1)
{
noteswriter.WriteLine(item);
toolStripProgressBar1.ProgressBar.PerformStep();
}
noteswriter.Dispose();
noteswriter.Close();
This gives me an output such as:
{colA = AccountA,colB = Number1,colC = AccountA }
{colA = AccountA,colB = Number1,colC = AccountHolderA }
{colA = AccountA,colB = Number1,colC = Address1 }
{colA = AccountA,colB = Number1,colC = Address2 }
{colA = AccountB,colB = Number2,colC = AccountA }
{colA = AccountB,colB = Number2,colC = AccountHolderB }
{colA = AccountB,colB = Number2,colC = Address1 }
I don’t know how to get the CSV file to be written as:
AccountA,Number1,AccountA,AccountHolderA,Address1,Address2
AccountB,Number2,AccountA,AccountHolderB,Address
Any suggestion will be greatly appreciated. Thanks!
Try this:
EDIT: Here’s how to make the number of columns equal.