txt file read/overwrite/append. Is this feasible? (Visual C#)
<p>I'm writing a program for some data entry I have to periodically do. I have begun testing a few things that the program will have to do but i'm not sure about this part.</p>

<p>What i need this part to do is:</p>

<p>read a .txt file of data</p>

<p>take the first 12 characters from each line</p>

<p>take the first 12 characters from each line of the data that has been entered in a multi-line text box</p>

<p>compare the two lists line by line</p>

<p>if one of the 12 character blocks from the multi-line text box match one of the blocks in the .txt file then overwrite that entire line (only 17 characters in total)</p>

<p>if one of the 12 character blocks from the multi-line text box DO NOT match any of the blocks in the.txt file then append that entire line to the file</p>

<p>thats all it has to do.</p>

<p>i'll do an example:</p>

<p>TXT FILE:</p>

<pre><code>G01:78:08:32 JG05
G08:80:93:10 JG02
G28:58:29:28 JG04
</code></pre>

<p>MULTI-LINE TEXT BOX:</p>

<pre><code>G01:78:08:32 JG06
G28:58:29:28 JG03
G32:10:18:14 JG01
G32:18:50:78 JG07
</code></pre>

<p>RESULTING TXT FILE:</p>

<pre><code>G01:78:08:32 JG06
G08:80:93:10 JG02
G28:58:29:28 JG03
G32:10:18:14 JG01
G32:18:50:78 JG07
</code></pre>

<p>as you can see lines 1 and 3 were overwriten, line 2 was left alone as it did not match any blocks in the text box, lines 4 and 5 were appended to the file.</p>

<p>thats all i want it to do.</p>

<p>How do i go about this?</p>

<p>Thanks in advance</p>

<p>Edit</p>

<p>The code i'm using is this:</p>

<pre><code>        private void WriteToFile()
    {
         // Read all lines from file into memory
        System.IO.StreamReader objReader = new System.IO.StreamReader("Jumpgate List.JG");
        List&lt;String&gt; fileTextList = new List&lt;String&gt;();
                 do
                     {
                         fileTextList.Add(objReader.ReadLine());
                     }
                 while (objReader.Peek() != -1);

                 objReader.Close();

         // Read all lines from the Input textbox into memory
             System.IO.StringReader objReaderi = new System.IO.StringReader(txtInput.Text);
             List&lt;String&gt; inputTextList = new List&lt;String&gt;();
                 do
                     {
                         inputTextList.Add(objReaderi.ReadLine());
                     } 
                 while (objReaderi.Peek() != -1);

                 objReaderi.Close();

         for(int i=0;i&lt;fileTextList.Count;i++)
             {
                 for(int j=0;j&lt;inputTextList.Count;j++)
                  //compare the first 12 characters of each string
                  if (String.Compare(fileTextList[i], 0, inputTextList[j], 0, 12) == 0) // strings are equal
                     {
                       //replace the fileTextList string with the inputTextList string
                         fileTextList[i] = inputTextList[j];
                       // now that you have matched you inputTextList line you remember not to append it at the end
                        inputTextList[j] = String.Empty; // or nothing
                     }
             }

          for(int i=0;i&lt;inputTextList.Count;i++)
             {
                 if (!string.IsNullOrEmpty(inputTextList[i])) fileTextList.Add(inputTextList[i]);
              }

          System.IO.StreamWriter objWriter = new System.IO.StreamWriter("Jumpgate List.JG");

          // Overwrite the Jumpgate List.JG file using the updated fileTextList
          objWriter.Write(fileTextList);

          objWriter.Close();
</code></pre>

<p>}</p>

<p>However, when i open the txt file all i get is: System.Collections.Generic.List`1[System.String]</p>
