设为首页 加入收藏 网站搜索 繁體中文 中国建站网 — 站长资源平台

正则表达式中的组集合的使用

来源网络收集 作者:佚名 时间:2007-4-25 23:29:50 该文得分0

简单实例:

    string s = "2005-2-21";
    Regex reg = new Regex(@"(?<y>\d{4})-(?<m>\d{1,2})-(?<d>\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);

相关文章
广告赞助
网友评论

共有 0 位网友发表了评论,平均得分: 0 查看完整内容

用户名:

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

(注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码