2

I'm trying to unwrap a string in CsQuery. The functionality works, but I want to add a whitespace char between each tag.

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)

What is the best way to achieve this effect?

CosX
  • 1,920
  • 2
  • 15
  • 25

1 Answers1

0

I figured it out! I now iterate through all the elements and add a whitespace before the unwrap.

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
CosX
  • 1,920
  • 2
  • 15
  • 25