简体   繁体   English

如何用数组替换txt文件?

[英]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). 我用txt文件制作了一个数组,现在我想替换此txt文件中的数组(像在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. 因为我编辑了数组,现在我想再次替换txt文件,我希望它是可能的,并且我希望它可以使用细分线。

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

this is the line where i make a array of my txt. 这是我在其中输入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. 这是我所做的编辑,现在我想将其放回到txt文件中,这是我遇到很多问题的地方。

Just use WriteAllLines method. 只需使用WriteAllLines方法。 It will replace the contents of the file if the file exists. 如果文件存在,它将替换文件的内容。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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