I am doing a project where I have to read data from a .txt file and then insert each row into a table using a query.
Now, for example, the contents of the text file will be
11111
1111x
22222
2222x
33333
3333x
etc.
Now that you see that the alternate row is almost repeating, so I would like to remove the alternate rows so that the available data becomes
11111
22222
33333
and then process the rest of my codes.
Is there any way to do this?
So far I have used a list of arrays to get this
using (StreamReader sr = new StreamReader(Server.MapPath("03122013114450.txt"), true))
{
string txtValues = sr.ReadToEnd();
string[] txtValuesArray1 = Regex.Split(txtValues, "\r\n");
ArrayList array = new ArrayList();
foreach (string value in txtValuesArray1)
{
array.Add(value);
}
for (int i = 0; i < array.Count; i++)
{
if (array.Count % 2 != 0)
array.RemoveAt(i + 2);
else
array.RemoveAt(i + 1);
}
}
The main idea is to remove the alternative lines so that they are from the arraylist index from the text file.
source
share