我正在寻找解决方案来删除具有特定单词的两个符号之间的部分文本,例如:
用我的话列出:
Anny
Thomas
Andreas
要过滤的全文:
<name list>
<name id="bla bla bla"
anny is very good girl
</name>
<name id="jark"/>
<name id="Thomas"
specific style
</name>
<name id="andreas" 30/>
<name id="ehl"
very nice
</name>
</name list>
在此示例中,我想删除包含我的单词的文本,但它们也在<name
and</name>
或<name
and/>
符号之间,因此输出将是:
<name id="jark"asdasdasdasd/>
这是我来的代码:
Dim todelete() As String = File.ReadAllLines("C:\Temp\todelete.txt")
Dim doc As XDocument = XDocument.Load("C:\Temp\test.txt")
For Each badname As String in todelete
Dim e As XElement = From element
In doc.Elements("name list").Elements("name")
Where element.Attribute("name").Value = badname
Select element
e.Remove()
doc.Save()
Next