In my code I pass a number of lines that I want to take from the csv and then, for each line, iterates the elements that make up the csv but I am not getting it, I put the code
test.csv
gato,casa,http,antonio;
perro,abanico,https,libro;
C# class Program {
static void Main(string[] args)
{
int contador = 0;
int num_lineas;
string[] array = null;
var ruta = Directory.GetCurrentDirectory();
ruta += "/articulo.csv";
num_lineas = File.ReadAllLines(ruta).Length;
array = File.ReadAllText(ruta).Split(';');
while (contador < num_lineas)
{
while (true)
{
var a = array[contador].Split(',')[0];
var b = array[contador].Split(',')[1];
var c = array[contador].Split(',')[2];
var d = array[contador].Split(',')[3];
var e = array[contador].Split(',')[4];
var f = array[contador].Split(',')[5];
var g = array[contador].Split(',')[6];
var h = array[contador].Split(',')[7];
var i = array[contador].Split(',')[8];
var imagen = array[contador].Split(',')[9];
Console.WriteLine(c);
Thread.Sleep(6000);
break;
}
File.Replace(array[contador]); //aqui tengo que borrar la linea que esta dentro del archivo csv
contador++;
}
Thread.Sleep(6000);
}
}
}
I have modified it like this now I want to delete the first line of the csv any idea....
Another solution could be to use Linq to read all the lines and in turn output them to a list of a defined class (for better object manipulation) instead of a
array
. For example, having the following class:Using Linq, you will be able to read the file, skip the first line, and in turn, evaluate that the file content contains the proper positions and length.