[RESOLVED] Searching a Large String
Hey
Well I haven't programmed for some time, so I'm a little rusty :o.
Basically I'm storing HTML within a variable, and I need to count the amount of times a specific element appears e.g. <h3 class=r> for now.
I thought of using a for each loop, and passing the string above into the parentheses of the loop (using a variable ofc) however for many reason's, I don't think this has a chance of working (won't bother explaining why, as I assume you can guess). Then thought of using the .Contains method of the string class, but I simply can't think of how to use it with what I'm trying to do.
Help appreciated.
Re: Searching a Large String
I was able to create a procedure to do this in about 5 minutes using .IndexOf(WORD, Starting Index).
Just declare an Index variable and have a While loop to keep going until .IndexOf(word, index) returns -1, while it loops, keep setting the index variable = to the next index of the word (+ the words length so you don't get stuck).
Re: Searching a Large String
try this. its the quickest way:
vb Code:
Dim wc As New Net.WebClient
Dim html As String = wc.DownloadString(url)
Dim rx As New System.Text.RegularExpressions.Regex("<h3 class=r>")
MsgBox(rx.Matches(html).Count)