找回密码
 注册
搜索
热搜: 回贴

ASP.net:正则表达式中的组集合的使用

2009-12-13 12:36| 发布者: admin| 查看: 76| 评论: 0|原作者: 回梦游仙

◆简单实例: strings="2005-......


简单实例:
string s = "2005-2-21";
Regex reg = new Regex(@"(?\d{4})-(?\d{1,2})-(?\d{1,2})",RegexOptions.Compiled);

Match match = reg.Match(s);
int year = int.Parse(match.Groups["y"].Value);
int month = int.Parse(match.Groups["m"].Value);
int day = int .Parse(match.Groups["d"].Value);
DateTime time = new DateTime(year,month,day);

最新评论

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-29 17:34 , Processed in 0.178267 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

返回顶部