日期:2014-05-20 浏览次数:20883 次
string[] str = File.ReadAllLines("D:\\1.txt", Encoding.Default);
DataTable dt = new DataTable();
Regex.Split(str[0], @"\s+").Where(t => t.Trim() != "").ToList().ForEach(t => dt.Columns.Add(t.Trim()));
for (int i = 1; i < str.Length; i++)
{
DataRow dr = dt.NewRow();
Regex.Split(str[i], @"\s+").Where(t => t.Trim() != "").Select((t, index) => dr[index] = t).ToArray();
dt.Rows.Add(dr);
}