当前位置: 首页 > 编程语言 > C#

根据部分ID列表过滤HtmlElements列表Share

时间:2023-04-10 23:03:51 C#

根据部分ID列表过滤HtmlElements列表包含来自另一个列表的id。所以我尝试了一些没有成功的事情。我从一个集合中得到一个列表并尝试过滤它。这是部分ID的列表。元素ID不同,它们的ID对应这个列表,开头是一些看似随机的数字。string[]ids={“btadminh_struct.description”、“thtmlb_textView_6”、“thtmlb_textView_7”、“btadminh_struct.object_id”、“thtmlb_textView_12”、“zbtsaleset_struct.po_number_sold”、“thtmlb_textView_17”、“thtmlb_textView_21”、“thtmlb_textView_24”、“btcustomerh_z_followupdate”","thtmlb_textView_29","btrefobjmain_ibibase","btrefobjmain_ibinstancedesc","btpartnerserviceto_struct.description_name","btpartnerset_contact_name","zzericempresp_struct.partner_no","zbtcsrower_struct.partner_no","btcustomerh_struct.zcomments","thtmlb_textView_19","contractadminh","btcustomerh_zcontracttype_descr","btrefobjmain_network_id","btrefobjmain_node_id","btrefobjmain_site_id"};元素ID看起来像这样:"C29_W87_V88_btrefobjmain_network_instance","C29_W87_V88_btrefobjmain_network_id__items","C29_W87_V88_btrefobjmain_network_id","C29_W87_V88_btrefobjmain_network_id-btn","C29_W87_V88_btrefobjmain_network_id__key","C29_W87_V88_thtmlb_label_2","C29_W87_V88_btrefobjmain_service_id__items","C29_W87_V88_btrefobjmain_service_id","C29_W87_V88_btrefobjmain_service_id-btn","C29_W87_V88_btrefobjmain_service_id__key","C29_W87_V88_thtmlb_label_3","C29_W87_V88_btrefobjmain_networkadap_id__items","C29_W87_V88_btrefobjmain_networkadap_id","C29_W87_V88_btrefobjmain_networkadap_id-btn","C29_W87_V88_btrefobjmain_networkadap_id__key",所以我把我的集合放到了我可以查询varelems=doc.All.Cast();我尝试了不同的方法,但都不起作用。我还想使用Linq并避免丑陋的二维foreach循环。有什么想法吗?所以像elems.Where(x=>ids.Any(id=>x.ID.Contains(id)))通过遍历elems中的每个项目(您的html元素列表)然后循环遍历您的id集合对于每个id,如果有的话匹配,则返回那个元素。以上是C#学习教程:根据部分ID列表过滤HtmlElements列表,希望大家多多关注~本文收集自网络,不代表一个位置。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处: