List<string> list = new List<string>(); foreach (string item in File.ReadAllLines(@"C:\Users\myx\Desktop\test.txt", Encoding.GetEncoding("GB2312"))) { var m = Regex.Match(item, @"(?<=^|\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)) list.Add(item); }
.Where=> 是linq吗? 可惜了,我项目是.net 2.0的,linq用不了!
List<string> list = new List<string>(); foreach (string item in File.ReadAllLines(@"C:\Users\myx\Desktop\test.txt", Encoding.GetEncoding("GB2312"))) { var m = Regex.Match(item, @"(?<=^|\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)) list.Add(item); } 谢谢``很周到贴心 结贴给分!
00:10:05([\w\W]*)00:10:05
pattern 就是上面的,取出第一个分组就好
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;
});
.Where=> 是linq吗?
.Where=> 是linq吗?
可惜了,我项目是.net 2.0的,linq用不了!
.Where=> 是linq吗?
可惜了,我项目是.net 2.0的,linq用不了!
List<string> list = new List<string>();
foreach (string item in File.ReadAllLines(@"C:\Users\myx\Desktop\test.txt", Encoding.GetEncoding("GB2312")))
{
var m = Regex.Match(item, @"(?<=^|\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))
list.Add(item);
}
可惜了,我项目是.net 2.0的,linq用不了!
List<string> list = new List<string>();
foreach (string item in File.ReadAllLines(@"C:\Users\myx\Desktop\test.txt", Encoding.GetEncoding("GB2312")))
{
var m = Regex.Match(item, @"(?<=^|\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))
list.Add(item);
}
谢谢``很周到贴心
结贴给分!