public interface DataParser
{
DataTable Parse(string fileName);
}
public class PlainDataParser : DataParser
{
private const char separator = '\t';
#region DataParser 成员
public DataTable Parse(string fileName)
{
DataTable dt = new DataTable();
using (StreamReader reader = File.OpenText(fileName))
{
string temp;
string[] parts;
if (!reader.EndOfStream)
{
temp = reader.ReadLine();
parts = temp.Split(separator);
foreach (string s in parts)
{
dt.Columns.Add(s);
}
while (reader.Peek() > -1)
{
temp = reader.ReadLine();
parts = temp.Split(separator);
dt.LoadDataRow(parts, true);
}
}
else
{
}
}
return dt;
}
#endregion
}