Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VB.NET Regex.Replace not working (array not updating)

It must be a really silly error that I just can’t see here… or my recent switch from .NET Framework to .NET8 plays tricks on me. I’m simply trying to get rid of HTML tags in an array of strings, and whilst debugging I see that my variable "l" gets updated properly, i.e. the Regex itself works. But the line isn’t updated in the array.

Would someone please point to my error? Thank you ever so much!

Here’s my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Private Function RemoveHTMLTags(content As String) As String()

    Dim lines() = content.Split(vbLf)
    For Each l In lines
        l = Regex.Replace(l, htmlRegexG, String.Empty)
        'l = ... more changes here
    Next
    Return lines

End Function

EDIT: Just to avoid confusion, htmlRegexG is defined as string "<\w>|</\w>" outside the method and it does change the variable!

>Solution :

You could update line(i) instead of l:

Private Function RemoveHTMLTags(content As String) As String()
    Dim lines() = content.Split(vbLf)
    For i As Integer = 0 To lines.Length - 1
        lines(i) = Regex.Replace(lines(i), htmlRegexG, String.Empty)
        'lines(i) = ... also modify the other changes
    Next
    Return lines
End Function
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading