首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

一个弱小的正则有关问题

2013-06-26 
一个弱小的正则问题MVC应用程序 一个地址栏 http://localhost:2222/News#!http://localhost:2222/News/?Is

一个弱小的正则问题
MVC应用程序 一个地址栏 http://localhost:2222/News#!http://localhost:2222/News/?IsG=1&gid=11

如何在后台页面程序 取得gid的Value和IsG 的Value? 

最好封装成一个方法   通过两个参数和Key 来找到Value
[解决办法]
手写的,有问题自己修改


 private static Dictionary<string, string> GetValue(string url, string parm1, string parm2)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            foreach (Match m in Regex.Matches(url, parm1 + @"=(?<value1>\w+)&" + parm2 + @"=(?<value2>\w+)"))
            {
                dic.Add(m.Groups["value1"].Value, m.Groups["value2"].Value);
            }
            return dic;
        }
        static void Main(string[] args)
        {
            string htmlurl = @"http://localhost:2222/News#!http://localhost:2222/News/?IsG=1&gid=11";
            Dictionary<string, string> dic = GetValue(htmlurl, "IsG", "gid");
            String file_name = "C:\\test.xls"; 
       }

热点排行