当前位置:编程学习 > JS >>

asp.net获取字符串中所有外链代码

因为http连接在html都是以"结束或者<结束,所以根据传入的https教程tr样式不区分大小写方式把字符串str含有的以递归的方式找出来。


private string gethttpstr(string str, string httpstr)
        {
            bool ishavevalue = false;
            int newlength = httpstr.length;
            string newstr = null;

            string httpendstring = "<";
             if (str.length >= newlength && str.contains(httpstr))
            {
                newstr = str.substring(str.indexof(httpstr, stringcomparison.ordinalignorecase) + newlength);
            }
            int startindex = 0;
            startindex = str.indexof(httpstr, stringcomparison.ordinalignorecase);
            int lengthindex = 0;
            string returnvalue = null;
            if (startindex >= 0)
            {
                if (newstr.indexof('"') != -1 && newstr.indexof('"') <= newstr.indexof(httpendstring))
                {
                    lengthindex = newstr.indexof('"') + newlength;
                }
                else if (newstr.indexof('"') == -1 && newstr.indexof(httpendstring) == -1)
                {
                    lengthindex = str.length;
                }
                else
                {
                    lengthindex = newstr.indexof(httpendstring) + newlength;
                }
                if (lengthindex == (newlength - 1))
                {

                    lengthindex = newstr.indexof(httpendstring) + newlength;
                }
                returnvalue = str.substring(startindex, lengthindex);
                ishavevalue = true;
            }
            returnvalue = replacespecialurl(returnvalue);
            return returnvalue + "  " + ((startindex + lengthindex) < str.length && startindex > 0 && ishavevalue ? gethttpstr(str.substring(startindex + lengthindex), httpstr) : null);

        }

补充:网页制作,js教程 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,