我试图在CsQuery中解包字符串。该功能有效,但我想在每个标签之间添加一个空白字符。
Dim fragment = CsQuery.CQ.Create(<div>some text</div><div>More text</div>)
Dim unwrapTags = New List(Of String) With {"div"}
For Each s In unwrapTags
fragment(s).Contents.Unwrap() 'Here I want to add a whitespace between every tag
Next
' Should outprint "some text More text ", not "some textMore text"
Return fragment.Render(CsQuery.OutputFormatters.HtmlEncodingMinimum)
实现这种效果的最佳方法是什么?
答案 0 :(得分:0)
我明白了!我现在遍历所有元素并在解包之前添加一个空格。
Public Function SanitizeString()
For Each s In unwrapTags
fragment.Each(AddressOf AddWhiteSpace)
fragment(s).Contents.Unwrap()
Next
End Function
Private Shared Sub AddWhiteSpace(obj As IDomObject)
obj.InnerText &= " "
End Sub