文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>正则表达式学习,使用.NET framework api

正则表达式学习,使用.NET framework api

时间:2011-04-01  来源:mrxliu

View Code  public static string Process(string input)
        {
            Regex r = new Regex(@"\$\{(?<custId>\d+):(?<attrib>\w+)}");
            return r.Replace(input, Evaluate);
        }

        static string Evaluate(Match match)
        {
            Customer c = new Customer { Name = "同志们", Ssn = "123", Company = "公司" };
            switch (match.Groups["attrib"].Value)
            {
                case "name":
                    return c.Name;
                case "ssn":
                    return c.Ssn;
                case "company":
                    return c.Company;
                default:
                    throw new Exception();
                    break;
            }
        }

        class Customer
        {
            public string Name { get; set; }
            public string Ssn { get; set; }
            public string Company { get; set; }
相关阅读 更多 +
排行榜 更多 +
贪吃蛇无尽大作战国际服

贪吃蛇无尽大作战国际服

休闲益智 下载
我的狗狗小游戏

我的狗狗小游戏

休闲益智 下载
糖果灾难内购版

糖果灾难内购版

模拟经营 下载