![](/img/trans.png)
[英]C# search all files in a directory that contain a string, then return that string
[英]C# string.ALL<> using contain to search a string - htmlagility
我正在尝试使用 htmlagility 包抓取HTML 文件。 我意识到这不是敏捷包的问题,而是与理解字符串操作有关,根据下面的示例代码,我期待“未找到”,但它返回为 Found。 它看起来像搜索字符而不是字符串。 如果我将 XYZ 放在 str1 中,则找不到结果。 有人可以帮助我如何获得期望的结果。
private void button2_Click(object sender, EventArgs e)
{
string str1 = "PBS" ;
string str2 = "JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ";
if ( str1.All(x=> str2.Contains(x)) )
{
MessageBox.Show(str2);
}
else
{
MessageBox.Show("Not Found");
}
}
我的实际编码如下,我也得到了我不想要的 html 节点。
string monthValues = " JAN FEB MAR APR MAY JUN JUL AUG OCT NOV DEC ";
var header = ROWS[rowCount + 1].Descendants("TH").Where(node => node.InnerHtml.ToString().Substring(0,2).All(x => monthValues.Contains(x))).ToList();
和 html 如下。 我也得到了具有“PBS”的“TH”节点
<tr>
<th class="l t colhd" rowspan="11"> 9494Q </th>
<th class="l t colhd" rowspan="3">PBS </th>
<th class="l t colhd">FEB2021</th>
</tr>
感谢你的帮助。
问候
该代码正在从 str2 中的 str1 中查找每个单独的字符。 因此字母 PB 和 S 都出现在 str2 中。 XY 和 Z 没有。
我想你只是想要
if (str2.Contains(str1))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.