0

I'm trying to append text to the end of a specific line of text in a text file in C#, I'm not getting the desired results. Here's the file

23 - 2546853  
24 - 2345548  
25 - 3458394

The first number is the Id that the numbers that follow are associated with. The problem comes in when I try to add a new number to an existing Id it does the following:

 23 - 2337980,
        232789423,
        423424898,
 24 - 2345548  
 25 - 3458394

instead of:

       23 - 2337980,232789423,423424898,
       24 - 2345548  
       25 - 3458394

Right now I'm using this solution to get the position of the line number, after that when I write to the text file after reading the position of the ID's line number, I use the value of the line number position as an argument for the StreamWriter.BaseStream.Seek() method and then I call the StreamWriter.Write() method. All help will be much appreciated.

icebat
  • 4,696
  • 4
  • 22
  • 36
  • Can you post the code you have now? – CKII Nov 08 '17 at 10:19
  • 1
    Could you use File.ReadAllLines, find & modify the required string in the array & then write back with File.WriteAllLines – PaulF Nov 08 '17 at 10:21
  • @CKII and PaulF Thank you for the input guys and sorry for the late response but my understanding of what was required for me to do was incorrect, all I had to do was take in an ID and a value which were separated by comma then the next ID and another value would simply go on to the next line even if it is the same ID which was much more easier to implement compared to what I thought I had to do. – Clifton Steenkamp Nov 13 '17 at 13:18

0 Answers0