简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM