C#按行读取TXT 然后只更改其中特定行,求助!

2025-02-28 19:17:34
推荐回答(2个)
回答1:

List result = new List();
String[] arr = System.IO.File.ReadAllLines("file_path");
string temp;
foreach(string item in arr)
{
string[] tmpArr = item.Split(new char[]{','});
tmpArr[1]=你的处理

result.Add(tmpArr[0]+","+tmpArr[1]);
}

System.IO.File.WriteAllLines("file_path",result.toArray(),Encoding.Default);

大概的思路,参考下

回答2:

全部读入,
改变部分数据,
全部写入。