I have code that performs an html scrape:
What I need to do is once I apply the regex to the scrape, I want to get the total number of elements (games) before I do any further processing.
AFAIK there is no way to get a "count" of the number of matches from the "Match" object, but there is with matchcollection?
Could someone tell me if there is a way to get a count from the regex before I do any processing?
Code:
Dim myConnection As New SqlConnection("server=(local);database=xxxx;Trusted_Connection=yes")
Dim strAddress As String = ("http:" & straddress & ".html")
Dim oRequest As WebRequest = WebRequest.Create(strAddress)
Dim oResponse As WebResponse = oRequest.GetResponse()
Dim oStream As Stream = oResponse.GetResponseStream()
Dim oStreamReader As New StreamReader(oStream, Encoding.UTF8)
Dim strData As String = oStreamReader.ReadToEnd()
Dim regGames As New Regex("[regexpattern]", RegexOptions.Singleline)
Dim mGames As Match = regGames.Match(strData)
***************************************
While mGames.Success
Dim writeGames As New SqlCommand( _
"INSERT [insert statement]", myConnection)
writeGames.Connection.Open()
writeGames.ExecuteNonQuery()
writeGames.Connection.Close()
Dim strGame As String = mGames.Groups(1).Value & " " & _
mGames.Groups(2).Value & " @ "
next game
mGames = mGames.NextMatch
strGame = strGame & mGames.Groups(1).Value & " " & _
mGames.Groups(2).Value()
print
Response.Write(strGame & "<br>")
next set and loop
mGames = mGames.NextMatch
End While
What I need to do is once I apply the regex to the scrape, I want to get the total number of elements (games) before I do any further processing.
AFAIK there is no way to get a "count" of the number of matches from the "Match" object, but there is with matchcollection?
Could someone tell me if there is a way to get a count from the regex before I do any processing?