using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PR_IA2_2010_Clases
{
static public class IO
{
///
/// Lectura de los datos de un fichero dado de tipo CVS que
/// transforma en una lista de arrays de tipo string.
///
/// fichero
///
static public List
{
string texto;
string[] filas;
List
try
{
System.IO.StreamReader sr =
new System.IO.StreamReader(fichero, System.Text.Encoding.Default, true);
texto = sr.ReadToEnd();
string[] caracteresDelimitadores = {"\r\n"};
//Creamos un lista de arrys de una forma rápida para
//tener cada dato por separado para su posterior tratamiento.
filas=texto.Split(caracteresDelimitadores,StringSplitOptions.RemoveEmptyEntries);
if (filas.Count()>0)
{
datos=new List
for (int i = 0;i< filas.Count(); i++)
{
datos.Add(filas[i].Split(','));
}
}
sr.Close();
return datos;
}
catch (System.IO.IOException ex)
{
throw new Exception(ex.Message);
}
catch (System.Exception ex)
{
throw new Exception(ex.Message);
}
return null;
}
}
}
No hay comentarios:
Publicar un comentario