Below is the C# code to remove specified rows from CSV file using script task
Add following references:
using System.IO;
using System.Collections.Generic;
Code
------
string line;
StreamReader sr = new StreamReader(@"E:\Test.csv");
List<String> file = new List<string>();
while (sr.Peek() >= 0)
{
line = sr.ReadLine();
if (line != "")
{
if (!line.StartsWith("#")) //line starts with #
{
if (!line.Contains("Summary")) //line contains string as summary
{
file.Add(line);
}
}
}
}
sr.Close();
File.WriteAllLines(@"E:\Test1.csv", file);
//File.WriteAllLines(@"E:\Test.csv", file);
Add following references:
using System.IO;
using System.Collections.Generic;
Code
------
string line;
StreamReader sr = new StreamReader(@"E:\Test.csv");
List<String> file = new List<string>();
while (sr.Peek() >= 0)
{
line = sr.ReadLine();
if (line != "")
{
if (!line.StartsWith("#")) //line starts with #
{
if (!line.Contains("Summary")) //line contains string as summary
{
file.Add(line);
}
}
}
}
sr.Close();
File.WriteAllLines(@"E:\Test1.csv", file);
//File.WriteAllLines(@"E:\Test.csv", file);
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.