日期:2014-05-16  浏览次数:20767 次

文本文档格式的数据筛选.
如图:

举个例子,
我想用c#代码筛选出 [时间] between 00:10:05 and 00:20:33 的数据,该如何做?


谢谢~
------解决方案--------------------
先用System.IO.File.ReadAllLines();读出所有行 

然后取每一行的前多少位

比较一下就好~~
------解决方案--------------------
导入SQL 或DataTable中,然后再搜索
------解决方案--------------------
var result = File.ReadAllLines(@"C:\Users\myx\Desktop\test.txt", Encoding.GetEncoding("GB2312")).Where(a => {
                var m=Regex.Match(a, @"(?<=^
------解决方案--------------------
\s)(\d{1,2}):(\d{1,2}):(\d{1,2})");
                int s = 0;
                if(!string.IsNullOrEmpty(m.Value))
                    s = Convert.ToInt32(m.Groups[1].Value) * 60*60+Convert.ToInt32(m.Groups[2].Value) * 60 + Convert.ToInt32(m.Groups[3].Value);
                if (s > (10 * 60 + 5) && s < (20 * 60 + 33))
                    return true;
                else
                    return false;
            });

------解决方案--------------------
引用:
如图:

举个例子,
我想用c#代码筛选出 [时间] between 00:10:05 and 00:20:33 的数据,该如何做?


谢谢~

直接将文本转换成二维表,然后进行筛选
------解决方案--------------------
引用:
Quote: 引用:

导入SQL 或DataTable中,然后再搜索

导入到DataTable之后用什么方法查询呢?


DataTable有select()
------解决方案--------------------
引用:
Quote: 引用:

Quote: 引用:

谢谢~我试下
.Where=>  是linq吗?

可惜了,我项目是.net 2.0的,linq用不了!

List<string> list = new List<string>();
            foreach (string