In my dataset, I have a field which stores text marked up with HTML. The general format is as follows:
<html><head></head><body><p>My text.</p></body></html>
I could attempt to solve the problem by doing the following:
REPLACE(REPLACE(Table.HtmlData, '<html><head></head><body><p>', ''), '</p></body></html>')
However, this is not a strict rule as some of entries break W3C Standards and do not include <head>
tags for example. Even worse, there could be missing closing tags. So I would need to include the REPLACE
function for each opening and closing tag that could exist.
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
Table.HtmlData,
'<html>', ''),
'</html>', ''),
'<head>', ''),
'</head>', ''),
'<body>', ''),
'</body>', ''),
'<p>', ''),
'</p>', '')
I was wondering if there was a better way to accomplish this than using multiple nested REPLACE
functions. Unfortunately, the only languages I have available in this environment are SQL and Visual Basic (not .NET).
REPLACE
is much the same as a loop (performance-wise). I would create a 2-dimentional array holding pairs of HTML tags and loop over the string attempting to replace the tags. The advantage is that you can modify (enrich) the array without changing your code.