代码如下:
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); }因为HTTP连接在html都是以"结束或者<结束,所以根据传入的httpStr样式不区分大小写方式把字符串str含有的以递归的方式找出来。