|
-
Jun 27th, 2009, 03:17 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Searching a Large String
Hey
Well I haven't programmed for some time, so I'm a little rusty .
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.
Learning C♯
Data Binding & Bound Controls - Objects and wizards will never be as intelligent as you, do it yourself! (Unless your Pro)
-
Jun 27th, 2009, 03:25 PM
#2
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).
-
Jun 28th, 2009, 09:41 AM
#3
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)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|