我有一个非常长的字符串,我想要完成的是删除该字符串中从字符串的<tr>
父标记到其结束标记</tr>
的部分。 (希望我足够清楚)。
因此,当我使用文本&#34;搜索集成&#34;
调用方法RemoveSection时 <tr>
<td class=\"SectionHeaderHolder\" colspan=\"4\">
<p class=\"SectionHeader\">Header XX<span class=\"help\">Help</span></p>
</td>
</tr>
<tr>
<td class=\"SectionHeaderHolder\" colspan=\"4\">
<p class=\"SectionHeader\">Search Integration<span class=\"help\">Help</span></p>
</td>
</tr>
<tr>
<td class=\"SectionHeaderHolder\" colspan=\"4\">
<p class=\"SectionHeader\">Header YY<span class=\"help\">Help</span></p>
</td>
</tr>
<p class=\"SectionHeader\">
<tr>
<td class=\"SectionHeaderHolder\" colspan=\"4\">
<p class=\"SectionHeader\">Header XX<span class=\"help\">Help</span></p>
</td>
</tr>
<tr>
<td class=\"SectionHeaderHolder\" colspan=\"4\">
<p class=\"SectionHeader\">Header YY<span class=\"help\">Help</span></p>
</td>
</tr>
答案 0 :(得分:1)
您可以使用HtmlAgilityPack。一个简单的LinqPad示例:
void Main()
{
string input = "<tr><td class=\"SectionHeaderHolder\" colspan=\"4\"><p class=\"SectionHeader\">Header XX<span class=\"help\">Help</span></p></td></tr>"
+ "<tr><td class=\"SectionHeaderHolder\" colspan=\"4\"> <p class=\"SectionHeader\">Search Integration<span class=\"help\">Help</span></p> </td> </tr>"
+ "<tr><td class=\"SectionHeaderHolder\" colspan=\"4\"> <p class=\"SectionHeader\">Header YY<span class=\"help\">Help</span></p> </td> </tr>";
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(input);
doc.DocumentNode.SelectSingleNode("//p[text()='Search Integration']").ParentNode.ParentNode.Remove();
string output = doc.DocumentNode.OuterHtml;
input.Dump();
output.Dump();
}
答案 1 :(得分:1)
虽然我仍然推荐接受的解决方案,但使用普通正则表达式可以做同样的事情
SELECT * FROM ( SELECT c.id,c.edit_date, c.name,l.title
FROM tableA c, tableb l
WHERE c.id = l.id
AND c.published_ind = 'Y'
AND lc.type_id != 4
AND TRIM(c.img_file) IS NOT NULL
ORDER BY DBMS_RANDOM.VALUE
)
WHERE ROWNUM = 1
order by case when c.edit_date = 'null'
then DBMS_RANDOM.VALUE
else DBMS_RANDOM.VALUE, c.edit_date desc
end