zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    201521123039《Java程序设计》第十三周学习总结
    201521123039 《java程序设计》第十二周学习总结
    网络15软工个人作业5——软件工程总结
    个人作业4——alpha阶段个人总结
    软件工程第五周 个人作业(201521123084)
    软件工程第三周 结对编程(201521123084)
    软件工程网络15个人阅读作业2(201521123084 林正晟)
    软件工程网络15个人阅读作业1(201521123084 林正晟)
    Java课程设计——博客作业教学数据分析系统(201521123084 林正晟)
    JAVA课程设计
  • 原文地址:https://www.cnblogs.com/daixingqing/p/2768250.html
Copyright © 2011-2022 走看看