title: Inputting a text file, adding text to each line, writing to a new file C#
body: <p>For a homework assignment I have to create a very simplified assembler for MIPS code.
  So we take in an input file of MIPS instruction then output a file with the associated binary for the input code. Each line of code must be mapped to a "memory" location which is just a hexadecimal value in front of the line, but we add/assign this "memory".</p>
  
  <p>Therefore, what I would like to do is read in each line from a text file and at the front I would like to append a value (starting memory address in hex + (line number * 4.) Then I would like to re-read the file. If I need to read the whole file in, create a new file with the memory assigned, then read that file that's fine but I imagine probably unneccesary.</p>
  
  <p>Our professor suggested a list, so here's what I have so far:</p>
  
  <pre><code>Console.WriteLine("Please enter the path to the input file:");
  string inp = Console.ReadLine();
  Console.WriteLine("Please enter the name of the new file:");
  string otp = Console.ReadLine();
  StreamReader inputFile = new StreamReader(inp);
  StreamWriter outputFile = new StreamWriter(otp);
  List&lt;string&gt; fileContents = new List&lt;string&gt;();
  while ((inp = inputFile.ReadLine()) != null)
       fileContents.Add(inp);
  </code></pre>
  
  <p>So my question is: How do I add a string to the beginning of each item in that list (fileContents)?</p>
  
  <p><em><strong>Edit:</em></strong>
  Followup on this: I have managed to do all of this so far, I've brought in my whole document, mapped memory locations to each line, etc. However, I need to further edit some of the lines that are in the list "inputLines" by deleting some information from them.</p>
  
  <p>The format will always be [0] Memory Address [1] Label or, if no label in this line then registers, operations, etc. [2]-[?] registers, operations, etc.
  Once I've mapped my memory to each line, any line that has a label I want to put into a dictionary with the index as the label and the memory address as the value contained, then get rid of the label. So - how do I delete that information from any line that contains it?</p>
  
  <pre><code>//go through each line, if any line's first "token" is a label, 
  //put it in the dictionary as the index with the memory address as the value
  //delete the label from the line
  for (int i = 0; i &lt; inputLines.Length; i++)
      {
         string[] token = inputLines[i].Split(new char[] { ' ', ',', '(', ')', ':' }, StringSplitOptions.RemoveEmptyEntries);
              string possibleLabel = token[1];
              if (opcodes.ContainsKey(possibleLabel) == false)
              {
                  labeltable.Add(possibleLabel, token[0]);
                  //at this point I want to delete the possibleLabel from the inputLines[i] and not deal with it anymore.
              }
  
          }
  </code></pre>
  
  <p>That does correctly map to my dictionary, so not worried about that part.</p>