如果我只知道部分字符串代码,请尝试从 csv 文件中删除一些条目
//open File
FileStream fs = new FileStream(filePath, FileMode.Open,
FileAccess.ReadWrite);
StreamReader sr = new StreamReader(fs);
//divide file entry for separate lines
string []line = sr.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
// find required entry and create new List without it
List<string> finalData = new List<string>();
foreach (var l in line)
{
if (!line.Contains((dateTimePicker1.Text.ToString().Trim() + ','+ eventNameDeleteTextBox.Text.ToString().Trim()+',')))
finalData.Add(l);
}
// convert to array
string toCsvoutput = string.Join(Environment.NewLine, finalData.ToArray());
// viewTextBox1.Text=toCsvoutput;
//updateFile
sr.Close();
FileStream fs1 = new FileStream(filePath, FileMode.Open,FileAccess.Write, FileShare.None);
StreamWriter sw = new StreamWriter(fs1);
sw.WriteLine(toCsvoutput);
sw.Close();
结果 - 什么都没发生,我错在哪里?