title: C# Best way to parse flat file with dynamic number of fields per row
body: <p>I have a flat file that is pipe delimited and looks something like this as example</p>
  
  <p>ColA|ColB|3*|Note1|Note2|Note3|2**|A1|A2|A3|B1|B2|B3</p>
  
  <p>The first two columns are set and will always be there.</p>
  
  <p>* denotes a count for how many repeating fields there will be following that count so Notes 1 2 3 </p>
  
  <p>** denotes a count for how many times a block of fields are repeated and there are always 3 fields in a block. </p>
  
  <p>This is per row, so each row may have a different number of fields. </p>
  
  <p>Hope that makes sense so far.</p>
  
  <p>I'm trying to find the best way to parse this file, any suggestions would be great.</p>
  
  <p>The goal at the end is to map all these fields into a few different files - data transformation. I'm actually doing all this within SSIS but figured the default components won't be good enough so need to write own code.</p>
  
  <p>UPDATE I'm essentially trying to read this like a source file and do some lookups and string manipulation to some of the fields in between and spit out several different files like in any normal file to file transformation SSIS package.</p>
  
  <p>Using the above example, I may want to create a new file that ends up looking like this</p>
  
  <p>"ColA","HardcodedString","Note1CRLFNote2CRLF","ColB"</p>
  
  <p>And then another file</p>
  
  <p>Row1: "ColA","A1","A2","A3"</p>
  
  <p>Row2: "ColA","B1","B2","B3"</p>
  
  <p>So I guess I'm after some ideas on how to parse this as well as storing the data in either Stacks or Lists or?? to play with and spit out later.</p>