Jordy Huijgens
Jordy Huijgens

Reputation: 23

How can I replace my txt file with an array?

I made a array out of a txt file and now i want to replace the array in this txt file (replace like in update). becouse i edited the array, and now i want to replace the txt file again , i hope its possible and i hope its possible with breaklines.

string[] linesa = File.ReadLines("file1.txt").ToArray();

this is the line where i make a array of my txt.

number = Array.IndexOf(linesa, commonElement);           
number = number + 1;    
email  = linesa[number];
linesa[number] = "";
number = number - 1;
linesa[number] = "";

this is the edit i made and now i want to put it back in the txt file this is where i have alot of problems with.

Upvotes: 0

Views: 50

Answers (1)

Selman Genç
Selman Genç

Reputation: 101731

Just use WriteAllLines method. It will replace the contents of the file if the file exists.

File.WriteAllLines("file1.txt", linesa);

Upvotes: 3

Related Questions