读书人

2012年6月-如何用正则取年月数

发布时间: 2012-06-14 16:00:31 作者: rapoo

2012年6月--怎么用正则取年月数
如题,对正则不是很熟,搞了半天都没搞出来,请求指教

[解决办法]

C# code
            string source = "2012年6月";            Regex reg = new Regex(@"(?<year>\d{4}).*(?<month>\d{1,2}).*");            Match mm = reg.Match(source);            MessageBox.Show(mm.Groups["year"].Value);            MessageBox.Show(mm.Groups["month"].Value);
[解决办法]
探讨

引用:
引用:

格式不会变,格式为2012年6月,谢谢楼上

那根本不用正则,用string.Substring()截取就行了啊

string source = "2012年6月";
string source1=source.Substring(0,4);
string source1=source.Substring(5,1);

……

读书人网 >C#

热点推荐