using System;
using System.IO;
namespace ReaderCSV
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("CSV READER");
Console.WriteLine("--------------------------------------");
Console.Write("Enter name of file .csv: ");
string nameFile = Console.ReadLine();
StreamReader myfile;
string cadena;
int position;
try
{
myfile = new StreamReader(nameFile, System.Text.Encoding.Default);
string line;
do
{
line = myfile.ReadLine();
if ((line != null) && (line != ""))
{
try
{
line = line.Replace("\"", "");
position = line.IndexOf(';');
cadena = line.Substring(0, position);
line = line.Remove(0, position + 1);
Console.WriteLine(cadena + "\n");
position = line.IndexOf(';');
cadena = line.Substring(0, position);
line = line.Remove(0, position + 1);
Console.WriteLine(cadena + "\n");
position = line.IndexOf(';');
cadena = line.Substring(0, position);
line = line.Remove(0, position + 1);
Console.WriteLine(cadena + "\n");
cadena = line.Substring(0);
Console.WriteLine(cadena + "\n");
}
catch (Exception e)
{
Console.WriteLine("Error !!! " + e.Message);
}
}
}
while (line != null);
}
catch (Exception e)
{
Console.WriteLine("Error !!!" + e.Message);
}
}
}
}