I am trying to extract querystring values from a htmldocument. It contains a number of anchor links with a querystring parameter called id. I would like to get all the ids in a commaseperated string. How can I fix this? So I would like to get: Result = {1,2,3,4,5}
vb.net code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim str As String() = GetParagraphs(System.IO.File.ReadAllText(Server.MapPath("TextFile1.html")))
Response.Write(str)
End Sub
Private Shared Function GetParagraphs(ByVal data As String) As String()
Dim result As New List(Of String)
Dim m As Match = Regex.Match(data, "http://mywebsite.com/mydetails.aspx?id")
While (m.Success)
result.Add(m.Value)
m = m.NextMatch()
End While
Return result.ToArray()
End Function
TextFile.html
<a href="http://mywebsite.com/mydetails.aspx?id=1"
target="_blank"></a>
<a href="http://mywebsite.com/mydetails.aspx?id=2"
target="_blank"></a>
<a href="http://mywebsite.com/mydetails.aspx?id=3"
target="_blank"></a>
<a href="http://mywebsite.com/mydetails.aspx?id=4"
target="_blank"></a>
<a href="http://mywebsite.com/mydetails.aspx?id=5"
target="_blank"></a>
You can use this modification to your GetParagraphs method: