我遇到的问题是这样的,有一个文件夹,里面有很多文本文件:比如 张三.txt
李四.txt 王五.txt.....
每个文本文件的内容各不相同 但其中有一段结构大致相同 比如 张三.txt有这段内容,这段内容前面还有其他内容,我需要截取这段内容,其它文本文件:比如李四 王五 都有这些内容 只是数据不一样,所在的行也不一样
下面是张三.txt要截取的内容
#考试排名#
日期 参加考试人数 环比增减 环比变化(%)
─────────────────────────────────────
2015-05-30 55 -14 -30.65
2015-04-30 50 -17 -26.51
2015-03-31 45 12 11.21
我的想法是把每个人的这段数据读出来 并且用每个人的名字或者说文本文件的名称作为一个字段,把上面的读到datatable 或数据库中

希望老师帮我指点,该如何写,最好能给个事例,多谢老师
忘了说一下是c#呵呵
顺便贴一下比较详细的文本内容:
最后生成的datatable

最好上传一个例子文件,这样好帮你看,不知道你的数据前是不是还有一个空格。另外以后提问不要带上我的名字。其实这里有很多比牛很多的专家,他们也可以解决你的问题。或许解决的更好。
呵呵,不好意思,老师热情,道行高,所以就。。。 前面有很多空格呀什么的 就希望在◆考试排名◆这里开始截取
这里可能是3行也可能是5行,后面就没有数据了
老师 或者像这样的一个文本文件
好的,老师http://pan.baidu.com/s/1o8kYCtG 您帮看看 ◆考试排名◆的行不一定是固定的
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Text.RegularExpressions;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Controls.Add(new DataGridView()
{
Height = ClientSize.Height - 60,
Top = 10,
Width = ClientSize.Width - 20,
Left = 10,
Name = "dgv"
});
Controls.Add(new Button()
{
Name = "btn",
Top = Controls["dgv"].Height + 20,
Left = 10,
Text = "Load"
});
Controls["btn"].Click += new EventHandler(btn_Click);
}
private void btn_Click(object sender, EventArgs e)
{
OpenFileDialog ofn = new OpenFileDialog();
if (ofn.ShowDialog() == DialogResult.OK)
{
var query = File.ReadAllLines(ofn.FileName).SkipWhile(x => !Regex.IsMatch(x, @"\d{4}\-\d{2}\-\d{2}"))
.Select(x => x.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries))
.Select(x => new { 日期 = x[0], 人数 = x[1], 增减 = x[2], 增减率 = x[3] }).ToList();
var dgv = Controls["dgv"] as DataGridView;
dgv.DataSource = query;
}
}
}
}
老师厉害,多谢,呵呵,没有老师干不了的