读书人

求圣人指教求一段C#代码实现从txt

发布时间: 2012-09-03 09:48:39 作者: rapoo

求高人指教,求一段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(','); 

读书人网 >C#

热点推荐