I got below StripHTMLTags function code which work fine in VBSCript, now I want same function to be written C#
Function StripHTMLTags(ByVal sHTML)
Dim objRegExp, sOutput
sHTML = Replace(Replace(Trim(sHTML & ""), "<", "<"), ">", ">") ' ** PREVENT NULL ERRORS **
If Len(sHTML) > 0 Then
Set objRegExp = New RegExp
With objRegExp
.IgnoreCase = True
.Global = True
.Pattern= "<[^>]+>"
' ** REPLACE ALL HTML TAG MATCHES WITH THE EMPTY STRING **
sOutput = .Replace(sHTML, "")
End With
Set objRegExp = Nothing
StripHTMLTags = sOutput
Else
StripHTMLTags = ""
End If
End Function
Please suggest as it is really confusing me.
Have you tried Regex.Replace?
Example:
RegExr