Reputation: 1771
Is there any way in VB.NET to remove all of the whitespaces between tags in HTML?
Say, I've got this:
<tr>
<td>
The string I've built is an entire HTML document, and it counts everything before those tags as legitimate space, so I need to trim it out. Is there a reg ex or function out there I could use to do this?
Thanks
Upvotes: 0
Views: 5201
Reputation:
The above solution is a good start, but the code is slightly wrong and the regular expression is more than it needs to be. Here's the minimum that you would need to do in this case:
Dim RegexObj As New Regex(">[\s]*<")
NewText = RegexObj.Replace(OldText, "><")
The \n
is unnecessary because .Net includes the carriage return and line feed characters in the set of whitespace characters (\s)
. Not sure about other languages. And if it didn't, you would also need to include the \r
character because a Windows newline is \r\n
in a regex, not just \n
.
Upvotes: 0