• url地址栏参数


      
      public string getUrlPara(string sUrl, string paraName)
        {
            string sReg = "(?:\\?|&){1}" + paraName + "=([^&]*)";
            System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(sReg,
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            return re.Match(sUrl).Groups[1].Value;
        }

       ///
    <summary> /// 获取Url /// </summary> /// <param name="name"></param> /// <param name="value"></param> /// <returns></returns> protected string getUrl(string name, string value) { string url = System.Text.RegularExpressions.Regex.Replace(Request.Url.Query.Trim(), @"^\?", ""); url = System.Text.RegularExpressions.Regex.Replace(url, "^" + name + "=.*?&|" + name + "=.*?&", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "&{0,1}" + name + "=.*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "^page=.*?&|page=.*?&", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "&{0,1}page=.*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); if (url.Trim() == "") { return "?" + name + "=" + value; } return getReplaceUrl("?" + name + "=" + value + "&" + url, "key"); } /// <summary> /// 获取Url /// </summary> /// <param name="name"></param> /// <param name="value"></param> /// <returns></returns> protected string getReplaceUrl(string url, string name) { url = System.Text.RegularExpressions.Regex.Replace(url, "^" + name + "=.*?&|" + name + "=.*?&", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "&{0,1}" + name + "=.*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "^page=.*?&|page=.*?&", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); url = System.Text.RegularExpressions.Regex.Replace(url, "&{0,1}page=.*", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); return url; }
    function getUrlPara(paraName) {
                var sUrl = location.href;
                var sReg = "(?:\\?|&){1}" + paraName + "=([^&]*)"
                var re = new RegExp(sReg, "gi");
                re.exec(sUrl);
                return RegExp.$1;
            }
    function getUrl(name, value) {
                var _cpath = window.location.href;
                var _css = _cpath.indexOf('?');            
                var url = "";
                if (_css > -1) { url = _cpath.substring(_css + 1); }
                var sReg1 = "^" + name + "=.*?&|" + name + "=.*?&";
                var re1 = new RegExp(sReg1, "gi");
                url = url.replace(re1, "");
                var sReg2 = "&{0,1}" + name + "=.*";
                var re2 = new RegExp(sReg2, "gi");
                url = url.replace(re2, "");
                var sReg3 = "^page=.*?&|page=.*?&";
                var re3 = new RegExp(sReg3, "gi");
                url = url.replace(re3, "");
                var sReg4 = "&{0,1}page=.*";
                var re4 = new RegExp(sReg4, "gi");
                url = url.replace(re4, "");            
                if ($.trim(url).length < 1) { return "?" + name + "=" + value; }
                return getReplaceUrl("?" + name + "=" + value + "&" + url, "key");
            }
            function getReplaceUrl(url, name) {
                var sReg1 = "^" + name + "=.*?&|" + name + "=.*?&";
                var re1 = new RegExp(sReg1, "gi");
                url = url.replace(re1, "");
                var sReg2 = "&{0,1}" + name + "=.*";
                var re2 = new RegExp(sReg2, "gi");
                url = url.replace(re2, "");
                var sReg3 = "^page=.*?&|page=.*?&";
                var re3 = new RegExp(sReg3, "gi");
                url = url.replace(re3, "");
                var sReg4 = "&{0,1}page=.*";
                var re4 = new RegExp(sReg4, "gi");
                url = url.replace(re4, "");
                return url;
            }

     string str = QConnectSDK.CustomWebRequest.getResponse("http://www.baidu.com/", QConnectSDK.Method.GET, null);
            Regex reg = new Regex("<a\\s+href\\s*=\\s*\"?(.*?)[\"|>]", RegexOptions.IgnoreCase);
            MatchCollection mats = reg.Matches(str);
            string aa = "";
            foreach (Match mat in mats)
            {
                aa += mat.Groups[1].Value + "<br />";
            }
            Response.Write(aa);

  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    【手绘漫画】图解LeetCode之最长上升子序列(LeetCode300题),贪心算法 + 二分查找
    C 语言编程 — GDB 调试工具
    【debug】Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
    tf.expand_dims()函数解析(最清晰的解释)
    C 语言编程 — 堆栈与内存管理
    C 语言编程 — 输入/输出与文件操作
    C 语言编程 — 头文件
  • 原文地址:https://www.cnblogs.com/daixingqing/p/2768250.html
Copyright © 2020-2023  润新知