首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

求圣人指教,求一段C#代码,实现从txt文件中选取所有时间记录

2012-09-03 
求高人指教,求一段C#代码,实现从txt文件中选取所有时间记录。我是C#新手,在学习中遇到了一个难题,就是正则

求高人指教,求一段C#代码,实现从txt文件中选取所有时间记录。
我是C#新手,在学习中遇到了一个难题,就是正则表达式的用法,求一段代码,可以实现从txt文件中条件选取所有时间记录,例如2012.08.28,2001.09.09这样的日期全部可以提取出来,并在一个textbox中显示出来,谢谢大家啦!!!

[解决办法]

C# code
            StreamReader reader = new StreamReader("c:\\1.txt",Encoding.Default);            string source = reader.ReadToEnd();            Regex reg = new Regex(@"(?is)\d{4}\.\d{2}\.\d{2}");            MatchCollection mc = reg.Matches(source);            foreach (Match m in mc)            {                MessageBox.Show(m.Value);            }
[解决办法]
C# code
       StreamReader reader = new StreamReader("c:\\1.txt", Encoding.Default);            string source = reader.ReadToEnd();            Regex reg = new Regex(@"(?is)\d{4}\.\d{2}\.\d{2}");            MatchCollection mc = reg.Matches(source);            string str = "";            foreach (Match m in mc)            {                str + m.Value + ",";            }            控件ID.Text = str.TrimEnd(','); 

热点排行