I have a text file with 7 number of columns. The columns are always same may be 7 or more sometimes. My text file is tab delimited
.
So i would like to know how can i set a search for all the columns that are available in my text file and delete that entire line.
Currently, i am writing a single function for each columns search and delete the file
. i need a common function to search the whole text file and append the line
Codes:
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());
}