【发布时间】:2015-02-18 13:04:05
【问题描述】:
我有一个包含 7 列的文本文件。列总是相同的,有时可能是 7 个或更多。我的文本文件是tab delimited。
所以我想知道如何设置对文本文件中所有可用列的搜索并删除整行。
目前,我正在为each columns search and delete the file 编写一个单一函数。我需要一个通用函数来搜索整个文本文件并附加该行
代码:
public void stack()
{
string old;
string iniPath = Application.StartupPath + "\\list.ini";
bool isDeleteSectionFound = false;
List<string> deleteCodeList = new List<string>();
using (StreamReader sr = File.OpenText(iniPath))
{
while ((old = sr.ReadLine()) != null)
{
if (old.Trim().Equals("[DELETE]"))
{
isDeleteSectionFound = true;
}
if (isDeleteSectionFound && !old.Trim().Equals("[DELETE]"))
{
deleteCodeList.Add(old.Trim());
}
}
}
StringBuilder sb = new StringBuilder();
using (var reader = new StreamReader(File.OpenRead(textBox1.Text)))
{
//;
List<string> data = new List<string>();
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split('\t');
if (values.Contains(deleteCodeList))// getting that error
continue;
//
data.Add(string.Join("\t", values));
}
}
File.WriteAllText(textBox1.Text, sb.ToString());
}
【问题讨论】:
标签: c# string text append text-files