When Mickey's colleague was tasked with changing <br>s into newlines, he wanted to cover all the bases. Since <br />, <Br />, <bR />, etc. are all valid HTML, he clearly had his work cut out for him.
Damn case-sensitive string comparison, he must've thought. This could be so much easier! Oh well, I guess there's only one way to do it... brute force, baby!
'Replace <br /> with vbCrLf If LCase(strTagLess).Contains("<br>") Or _ LCase(strTagLess).Contains("<br/>") Or _ LCase(strTagLess).Contains("<br />") Then strTagLess = Replace(strTagLess, "<br>", vbCrLf) strTagLess = Replace(strTagLess, "<Br>", vbCrLf) strTagLess = Replace(strTagLess, "<bR>", vbCrLf) strTagLess = Replace(strTagLess, "<BR>", vbCrLf) strTagLess = Replace(strTagLess, "<br/>", vbCrLf) strTagLess = Replace(strTagLess, "<Br/>", vbCrLf) strTagLess = Replace(strTagLess, "<bR/>", vbCrLf) strTagLess = Replace(strTagLess, "<BR/>", vbCrLf) strTagLess = Replace(strTagLess, "<br />", vbCrLf) strTagLess = Replace(strTagLess, "<Br />", vbCrLf) strTagLess = Replace(strTagLess, "<bR />", vbCrLf) strTagLess = Replace(strTagLess, "<BR />", vbCrLf) End If
Mickey wound up replacing his colleague's code with:
Regex.Replace(html, "<br ?/?>", vbCrLf, RegexOptions.IgnoreCase)
[Advertisement]
BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!