This method will take into account the case scenario where you have an attribute in the first div (I.E. <div class='bla'> <div> text </div> </div>
).
For completeness and to avoid unhandled exception you should check for edge cases (such as empty strings, malformed html...)
public string InnerDiv(string html)
{
var start_idx = html.IndexOf(">", html.IndexOf("<div", StringComparison.InvariantCulture), StringComparison.InvariantCulture) + 1;
var last_idx = html.LastIndexOf("</div>", StringComparison.InvariantCulture);
return html.Substring(start_idx, last_idx - start_idx);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…