Extract a particular div from string
suppose a huge text data is stored in string variable like
<form method="post" action="../Dialog.aspx" id="ctl00">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUBMGRkcTeMEXjXlquwdmAmnkFVfUymwaaSdYr/CV1hV+mxr6A=" />
</div>
<div id="frm">
<table class="form" border="0" cellpadding="0">
<tr>
<td class="labeltag">Name:</td>
<td class="inputtd">
<input name="ctl01$txtName" type="text" maxlength="100" id="ctl01_txtName" class="inputfield" />
</td>
</tr>
<tr>
<td class="labeltag">Subject:</td>
<td class="inputtd">
<input name="ctl01$txtSubjectject" type="text" maxlength="100" id="ctl01_txtSubjectject" class="inputfield" />
</td>
</tr>
<tr>
<td class="labeltag">Email:</td>
<td class="inputtd">
<input name="ctl01$txtEmail" type="text" maxlength="100" id="ctl01_txtEmail" class="inputfield" />
</td>
</tr>
<tr>
<td class="textfield" colspan="2">
Message:
<div class="messagefield">
<textarea name="ctl01$txtmessage" rows="7" cols="33" id="ctl01_txtmessage" class="message">
</textarea>
</div>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="ctl01$btnSubmit" value="Submit" id="ctl01_btnSubmit" class="button" />
<input type="submit" name="ctl01$btnCancel" value="Cancel" id="ctl01_btnCancel" class="button" />
</td>
</tr>
<tr>
<td colspan="2" style="开发者_运维知识库height:10px"></td>
</tr>
<tr>
<td colspan="2">
<div class="bottomline" id="loader">
</div>
</td>
</tr>
</table>
</div>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBwKni+1oAuj1kf0MAoWeuckCAqCHyBsC34bOwQQC1cvcnQsC67K1+giML7QhoV19G+plAUvDQ7ade0566ipNfJ+BXR02JW5IIQ==" />
</div>
from the above data i just need to extract a particlular div having is called "frm" .
so the whole div and its content will be extracted. i know this can be done with regex but i dont know which patter will work in my case.
i use the code to extract a particular div like
Regex search_string = new Regex("<div.*?id=\"frm\".*?>.*</div>");
Match match = search_string.Match(outputToReturn);
string section = match.Groups[0].Value;
but section has nothing....match not found. so how to do it. so please help. thanks
It looks like your string contains html document. In this case you really should use an HTML parser (there are plenty depending on the language). One that I know of is HtmlAgilityPack.
精彩评论