这是我的HTML:
<div id="tab1" class="tab_content">
<div id="dvreadmore"><?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> </title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div>
<p class="dgthreedigest">CL : Where petitioner raised same bills against respondent as well as its sister concern, winding up petition against respondent for non-payment of dues was to be dismissed - [2012] 19 taxmann.com 206 (Delhi)</p>
</div>
</body>
</html>
请参阅此网址(http://www.taxmann.com/taxmannflashes/whatsnew.aspx?sid=9578&stype=1)
WebResponse res = req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
string htmlResp = sr.ReadToEnd();
String htmlBody = "";
if (htmlResp.ToLower().Contains("<div id=\"dvreadmore\">"))
{
int startIndex = htmlResp.ToLower().IndexOf("<div id=\"dvreadmore\">");
//here i m getting first index value
// but when i pick last indext it awlays give me -1
int lastIndex = htmlResp.ToLower().IndexOf("</html>\n</div>");
我在Java编译器中做了同样的事情,选择最后一个索引并给出一定的值,但在C#Asp .Net中,我无法选择数据,它总是给出-1值。
如何选择最后一个索引?
答案 0 :(得分:0)
您必须将 lastIndex 视为
int lastIndex = htmlResp.ToLower().IndexOf("</html>\r\n</div>");
或
int lastIndex = htmlResp.ToLower().IndexOf("</html>" + Environment.NewLine + "</div");
它返回23195