-4

I want to edit some text files automatically, but I don't know what to used to do it.

I want to open a file, check all lines, if one line begins with a 'C', I remove first 39-characters, etc .. then save all the file with an other name.

I already have a portion of code :

var car = ligne[0];
if(car != 'C') { continue; }
ligne.Remove(0, 39);

I use StreamReader to read, but what is the simple way to read and save in another file ?

StepUp
  • 36,391
  • 15
  • 88
  • 148
BlackAlpha
  • 376
  • 1
  • 5
  • 15
  • 2
    [`File.ReadAllLines`](https://msdn.microsoft.com/en-us/library/system.io.file.readalllines) → modify lines in memory → [`File.WriteAllLines`](https://msdn.microsoft.com/en-us/library/system.io.file.writealllines). – Uwe Keim May 03 '16 at 14:47

1 Answers1

7

Try File.ReadAllLines, which opens a file, reads everything, closes the file and returns an array containing all lines.

Do your processing....

Then File.WriteAllLines to open a file, write data, and close the file.

Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84