Extracting specific data from a string and summing it according to values contained elsewhere in string
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/13627720/performing-a-subtotal-on-filtered-data-from-a-streamreader">Performing a subtotal on filtered data from a streamreader</a>  </p>
</blockquote>



<p>Data Set: Hundreds of lines of data in "file.dat", each ranging from 80-500 ASCII characters in length.</p>

<p>Located in each string, at specific locations (fixed width not delimited), are 4 relevant pieces of information. </p>

<p>1) -NUMBERS- Always located in the first 3 characters of each string, is a number that states whether the string is relevant to me or not. If it contains any of 210,310 or 410 then I want to process this line, otherwise I want to ignore it.</p>

<p>2) -LETTERS- This information's location is dependent on whether the first 3 digits were 210, 310 or 410. If it is 210, then I want the algorithm to look at the values (always letters), contained in location 406-409. If the first 3 digits were 310, then I need the values from 322-325, and if 410, then what I need is in 478-481.</p>

<p>3 &amp; 4) -NUMBERS- The final 2 pieces of information are numbers, one of which will always be 0, the other will be > 0. Given that I cannot tell which is going to be the nonzero, I wish to add them together. These numbers are in the following locations:</p>

<pre>
       FIRST NUMBER LOCATION  SECOND NUMBER LOCATION             

210: ......... 129-140 ......................................142-153 

310: ..........113-124 ......................................126-137

410: ..........113-124  ......................................126-137 
</pre>

<p>What I need to do with this is provide subtotals for each combination of letters in 2). The range of values for 2) is only about 4-5 different arrangements of letters (ABCD, AAAA,BBBB,CCCC,DDDD), so my final output would be:</p>

<pre>
210 AAAA "Total number"

210 BBBB "Total number"

.

.

.

410 DDDD "Total number"

410 ABCD "Total number"
</pre>

<p>etc. for all combinations of the numbers and letters (15 maximum). </p>

<p>I hope this is clear,
Thanks in advance.</p>

<p>EDIT: CURRENT CODE:</p>

<p>i'm currently trying to go about it with a series of if's and lots of var's, hope this code pastes: </p>

<pre><code>class Program
{
    static void Main()
    {
        // Read in a file line-by-line, and store in a List.
        List&lt;string&gt; list = new List&lt;string&gt;();
        using (StreamReader reader = new StreamReader("file.dat"))
        {
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                var beginning = line.Substring(0, 3);
                // building this up atm
                // var letters210 = line.Substring(129,11);
                if (beginning != "210" &amp;&amp; beginning != "310" &amp;&amp; beginning != "410")
                    continue;

                list.Add(line); // Add to list.
                Console.WriteLine(line); // Write to console.
            }
        }
    }
}
</code></pre>
